【发布时间】:2013-12-26 00:23:45
【问题描述】:
我已经阅读了一些关于静态和动态单元格不兼容的帖子,但我想知道是否有针对我的情况的解决方法。
我有一个静态表(由UITableViewController 处理)。我在其中一个单元格中放置了一个动态表。代表和数据源是两个表的UITableViewController,只要内部动态表的行数小于静态表,它就可以很好地工作。当动态表格的单元格比静态表格多时,我会收到 index i beyond bounds 异常。
我假设单元格的总数以某种方式静态定义并由两个表共享,但无法真正理解到底发生了什么。有人遇到过类似的问题并找到了解决方法吗?
编辑
这是我的numberOfRowsInSection 方法。在我的委托/数据源的每个方法中,我检查调用表是动态表 (_tableOptions) 还是静态表(在这种情况下,我调用父方法)。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == _tableOptions) {
// I return here the number of rows for the dynamic inner table
} else {
return [super tableView:tableView numberOfRowsInSection:section];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == _tableOptions) {
static NSString *simpleTableIdentifier = @"cellOptions";
CellOptions *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
// Doing some stuff with my cell...
return cell;
} else {
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}
}
【问题讨论】:
-
您能否向我们展示有关数据源的代码。
-
你能把你写在cell配置方法中的代码粘贴过来吗?
-
感谢@KudoCC,我放了一些代码,希望能说明我如何处理指向同一个控制器的两个表。
-
我需要
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath实现和超出范围的数组的详细信息。 -
@KudoCC 刚刚更新了我的答案。我无法控制导致问题的数组,我猜这是
UITableViewController用来存储静态视单元的数组。
标签: ios objective-c uitableview