【问题标题】:uitableview hiding 2 cells from scrolluitableview 从滚动中隐藏 2 个单元格
【发布时间】:2014-01-08 21:24:47
【问题描述】:

做了一个表格视图,它根本没有意义,但我的表格视图隐藏了一些单元格。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 25;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell==nil){
        cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
    object= [self.results objectAtIndex:indexPath.row];
    cell.textLabel.text=[object valueForKey:@"hLabel"];
    return cell;
}

它确实渲染了 25 个单元格,但我最多只能查看 23 个单元格。下面隐藏了 2 个单元格。虽然如果我进一步滚动我可以看到它们,但如果我离开滚动视图会返回,第 23 个是最后一个单元格。因此用户无法选择 24 或 25。
即使我减少单元格数,假设为 23,tableview 仍然隐藏 2 个单元格,并且我无法访问它们,因为滚动在 2 个单元格之前结束。

【问题讨论】:

  • 你的视图中除了tableview还有其他对象吗?如果是这样,用代码设置 tableview 框架。高度应该像 (view height-tableview Yaxis)

标签: ios iphone ios7


【解决方案1】:

我认为您的 tableview 高度大于屏幕高度。 降低 tableview 的高度(使其适合视图绑定),它将显示所有单元格。

并且还要检查这个 autoresizing 约束是否在 tableview 的 zib/storyboard 中设置。

【讨论】:

  • 我同意你的观点,但我不认为Decrease the height of the tableview 是一个好的解决方法。最好在 viewDidAppear 方法中设置框架或在 Interface Builder 中设置约束(取决于在视图层次结构中添加 tableview 的方式)。
  • @zbMax 是的,我同意。你可以看到我添加了约束。通过减小 tableview 的大小,我的意思是设置它的框架以适应视图边界。
  • 我减小了我的 tableview 的大小,现在它的显示效果很好。但我看不到任何这些自动调整大小的选项。我的表格视图选项以原始设置结束。但是问题已经解决了,所以一切都很好。
  • 那么缩小尺寸对你有帮助还是删除自动布局对你有帮助?
  • 两者都有效,但删除自动布局感觉更合适的解决方案。
【解决方案2】:

我遇到了类似的问题,但我不知道如何解决,但是当我取消选中 Autolayout 时,问题得到了解决。尝试关闭自动布局。希望对你也有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多