gpt4 book ai didi

ios - 静态单元格内的 UITableView

转载 作者:行者123 更新时间:2023-11-29 10:42:26 24 4
gpt4 key购买 nike

当将 UITableView 放入 UITableViewController 中另一个 UITableView 的静态单元格时,我遇到了问题。如果 self.skillsTableView 的单元格多于 self.tableView 我的应用程序崩溃并出现异常:

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayI objectAtIndex:]: index 6 beyond bounds [0 .. 5]'

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *skillsCellIdentifier = @"skill_cell";
if (tableView == self.skillsTableView) {
NSLog(@"GET DYNAMIC %li", [tableView numberOfRowsInSection:0]);
ServicesTableViewCell *cell = (ServicesTableViewCell*)[tableView dequeueReusableCellWithIdentifier:skillsCellIdentifier forIndexPath:indexPath];
Services *skill = [self.servicesArray objectAtIndex:indexPath.row];
cell.titleLabel.text = skill.title;
cell.priceLabel.text = skill.price;
return cell;
}
else {
NSLog(@"GET STATIC %li", [super tableView:tableView numberOfRowsInSection:0]);
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}
}

和:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == self.skillsTableView) {
NSLog(@"DYNAMIC -- %li", self.servicesArray.count);
return self.servicesArray.count;
}
else {
NSLog(@"Static == %li", [super tableView:tableView numberOfRowsInSection:section]);
return [super tableView:tableView numberOfRowsInSection:section];
}
}

输出:

2014-05-28 09:19:55.461 SesApp[32289:60b] Static == 6
2014-05-28 09:19:55.461 SesApp[32289:60b] GET STATIC 6
2014-05-28 09:19:55.463 SesApp[32289:60b] GET STATIC 6
2014-05-28 09:19:55.464 SesApp[32289:60b] GET STATIC 6
2014-05-28 09:19:55.465 SesApp[32289:60b] GET STATIC 6
2014-05-28 09:19:55.466 SesApp[32289:60b] GET STATIC 6
2014-05-28 09:19:55.470 SesApp[32289:60b] DYNAMIC -- 0
2014-05-28 09:19:55.610 SesApp[32289:60b] Static == 6
2014-05-28 09:19:55.611 SesApp[32289:60b] DYNAMIC -- 7
2014-05-28 09:19:55.612 SesApp[32289:60b] GET STATIC 6
2014-05-28 09:19:55.613 SesApp[32289:60b] GET DYNAMIC 7
2014-05-28 09:19:55.617 SesApp[32289:60b] GET DYNAMIC 7
2014-05-28 09:19:55.619 SesApp[32289:60b] GET DYNAMIC 7
2014-05-28 09:19:55.621 SesApp[32289:60b] GET DYNAMIC 7
2014-05-28 09:19:55.623 SesApp[32289:60b] GET DYNAMIC 7
2014-05-28 09:19:55.625 SesApp[32289:60b] GET DYNAMIC 7
2014-05-28 09:19:55.627 SesApp[32289:60b] GET DYNAMIC 7
2014-05-28 09:23:08.897 SesApp[32289:60b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 6 beyond bounds [0 .. 5]'

最佳答案

在这两个委托(delegate)方法中,你不应该调用 super 方法。你应该把实际的实现放在那里。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == self.skillsTableView) {
return self.servicesArray.count;
}
else {
return NUMBER_OF_ROWS_FOR_PARENT_TABLE_VIEW_FOR_THIS_SECTION;
}
return 0;
}

您需要为 cellForRowAtIndexPath 方法做同样的事情。

关于ios - 静态单元格内的 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23884106/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com