i have a problem when put UITableView
inside static cell of another UITableView
in UITableViewController
. If self.skillsTableView has more cells than self.tableView my app crashes with exeption:
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayI objectAtIndex:]: index 6 beyond bounds [0 .. 5]'
Here is my code:
- (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];
}
}
and:
- (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];
}
}
Output:
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]'
I don't know why in my case this happens, but if someone in the future will face the same problem, i solve my issue in this way:
I add
UIContainerView
inside static cell, inUIContainerView
i haveUITableViewController
with this code:InsideTableViewController.h
InsideTableViewController.m
And in my
UITableViewController
with static cells:CustomTableViewController.m