我有這樣的錯誤在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