我有这样的错误在Xcode:的tableView numberOfRowsInSection
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 6 beyond bounds [0 .. 5]'
*** Call stack at first throw:
我使用此代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
int num_rows = 0;
switch (section) {
case 0:{
num_rows = [messageReceive count];
}
break;
case 1:{
num_rows = [messageSend count];
}
break;
return num_rows;
}
,但我尝试了很多代码,但同样的错误。我使用UITableView从JSON脚本php获取消息。在“messageReceive”中,有时我有0或1个或许多消息。 messageSend也一样。
THX
这是我的cellForRowAtIndexPath
// Configure the cell.
NSDictionary * dictMessReceive = [self.messageReceive objectAtIndex:indexPath.row];
NSDictionary * dictMessSend = [self.messageSend objectAtIndex:indexPath.row];
switch (indexPath.section)
{
case 0:
if (pseudoLabel.text =[dictMessSend objectForKey:@"sender"])
{cell.detailTextLabel.text = [dictMessSend objectForKey:@"receiver"];
cell.text= [dictMessSend objectForKey:@"message"];
}
break;
case 1:
if (pseudoLabel.text =[dictMessReceive objectForKey:@"receiver"])
{cell.detailTextLabel.text = [dictMessReceive objectForKey:@"sender"];
cell.text= [dictMessReceive objectForKey:@"message"];
}
else {
//cell.text = @"No message";
}
break;
}
return cell;
发布cellForRowAtIndexPath函数的代码。异常很可能来自那里。 –
那么你的'的tableView:的cellForRowAtIndexPath:'方法看起来像 – Intentss
看到我的编辑THX – XcodeMania