作为json中的新手,我想在tableview单元格中显示数据,但是当我填充tableview单元格时,它给出了上述异常。我之前曾问过这个问题,但没有确切的解决方案
我正在加载这样的响应
-(void)inboxmessagesGetSuccess:(FBGenericWebHandler*)handler response:(NSDictionary*)response
{
NSLog (@"Count %d", [[response objectForKey:@"messageResponse"] length] );
NSMutableArray *inboxArray = [[NSMutableArray alloc] init];
NSArray *firstarray=[[[response objectForKey:@"messageResponse"] objectAtIndex:1] objectForKey:@"messages"];
for(NSDictionary *tmp in firstarray)
{
NSMutableDictionary *messages=[[NSMutableDictionary alloc]init];
[messages setValue:[tmp objectForKey:@"messageId"] forKey:@"messageId"];
// [self.inboxmessagesarray addObject:messages];
}
[self.activitiesTableView_ reloadData];
}
但是当我填充细胞时
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *tableviewidentifier = @"cell";
tablecellTableViewCell *cell= [self.activitiesTableView_ dequeueReusableCellWithIdentifier:tableviewidentifier];
if(cell==nil)
{
cell = [[tablecellTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableviewidentifier];
}if(indexPath.row == [self tableView:tableView numberOfRowsInSection:indexPath.section] - 1){
// [[cell textLabel] setText:@"Load more records"];
}
UILabel *valuedate = (UILabel *)[cell viewWithTag:21];
UILabel *msg = (UILabel *)[cell viewWithTag:22];
UILabel *date = (UILabel *)[cell viewWithTag:23];
UILabel *time = (UILabel *)[cell viewWithTag:24];
valuedate.text=[[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"messageId"];
return cell;
}
这是一个例外。预先的thanx确实在其中停留了很多天。
最佳答案
将循环的self.lblArray 更改为 inboxmessagesGetSuccess 方法-(void)inboxmessagesGetSuccess:(FBGenericWebHandler*)handler response:(NSDictionary*)response
{
NSMutableArray *inboxArray = [[NSMutableArray alloc] init];
NSArray *firstarray=[[[response objectForKey:@"messageResponse"] objectAtIndex:1] objectForKey:@"messages"];
for(NSDictionary *tmp in firstarray)
{
NSMutableDictionary *messages=[[NSMutableDictionary alloc]init];
[messages setValue:[tmp objectForKey:@"messageId"] forKey:@"messageId"];
[self.inboxmessagesarray addObject:messages];
}
for (int i=0; i<self.inboxmessagesarray.count; i++)
{
[self.lblArray addObject:[NSString stringWithFormat:@"cell Number %d",i]];
}
[self.activitiesTableView_ reloadData];
}
关于ios - 由于未捕获的异常'NSRangeException'而终止应用程序,原因:-[__ NSArrayM objectAtIndex:]:索引0超出了空数组的范围'-2,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27395937/