我正在尝试向 tableView 添加 10 行,但不是在 for 循环中使用 insertRowsAtIndesPaths reloadData im,而是一次添加一行,而是在最后添加所有 10 行。这是我的代码...
if([[[[[notification userInfo] objectForKey:@"cityevent"]objectForKey:@"events"]objectForKey:@"event"] isKindOfClass:[NSArray class]])
{
[self.featuredEventTableView beginUpdates];
for(NSDictionary *tempDict in [[[[notification userInfo] objectForKey:@"cityevent"]objectForKey:@"events"]objectForKey:@"event"])
{
ESEvent *event=[[ESEvent alloc]init];
event.name=[tempDict objectForKey:@"name"];
if([[tempDict objectForKey:@"image"]isKindOfClass:[NSNull class]] || [tempDict objectForKey:@"image"] ==nil)
event.image=[UIImage imageNamed:@"category_default.png"];
else
{
event.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[tempDict objectForKey:@"image"]]]];
}
[events addObject:event];
NSIndexPath *ip=[NSIndexPath indexPathForRow:([events count]-1) inSection:0];
NSLog(@"row: %i section: %i",ip.row,ip.section);
[self.featuredEventTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:ip] withRowAnimation:UITableViewRowAnimationRight];
[self.featuredEventTableView endUpdates];
}
}
有什么建议么?