ios - 两个 UITableView 的 numberOfSectionsInTableView

标签 ios uitableview

我有两个 UITableView,它们根据 UISegmentControl.selectedSegmentIndex 出现。第一个表是grouped 样式,第二个是plain

NSFetchedResultsController 用于第一个 UITableView,NSMutableArray 用于第二个。

在我的numberOfSectionsInTableView中:

return [_fetchedResultsController.sections count];

在这种情况下,第二个 UITableView 的数据显示了 3 次(因为 FirstTableView section count = 3)。

我想要第二个 tableView numberOfSectionsInTableView

返回1;

最佳答案

在返回计数之前,您应该检查显示的是哪个表格 View 。为此,您可以使用 tableView 输入参数。

例如:-

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (tableView == self.firstTableView) //or (tableView == firstTableView)
       return [_fetchedResultsController.sections count];
    else 
       return 1;
}

关于ios - 两个 UITableView 的 numberOfSectionsInTableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15197817/

相关文章:

ios - 在显示之前更改 UIActionsheet 按钮文本和背景

ios - 未声明的委托(delegate)和 shouldStartLoadWithRequest

ios - UITableView选择——多选

iphone - 通过将行高设置为 0 来隐藏 UITableView?

ios - 选择表格 View 单元格时显示自定义 UIImageView

Android 运行时 : FATAL EXCEPTION: androidmapsapi-ZoomTableManager

ios - Xcode Instruments 跟踪比较

ios - cocos2d。对象类似于ccsprite但没有图片吗?

ios - 跨部分重新排序行时更新无效

ios - UIPageViewController -presentationCount 未触发