iphone - UITableView 一次添加带有动画的行,但延迟显着

标签 iphone objective-c ios uitableview

我正在尝试向 tableView 添加 10 行,而不是 reloadData 我在 for 循环中使用 insertRowsAtIndesPaths,但不是一次添加一行,而是在最后添加所有 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];
    }
}

有什么建议吗?

最佳答案

将开始更新调用移到 insertRowsAtIndexPaths: 调用之前。看看是否有帮助。我很惊讶这完全有效,因为您多次调用结束更新但只开始一次。

实际上,这可能仍然会非常快,您甚至都不会注意到。查看 NSTimer 或 GCD 的 dispatch_after 以错开更新。

关于iphone - UITableView 一次添加带有动画的行,但延迟显着,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11308271/

相关文章:

ios - 本地化 NSArray

iOS:如何从 Firebase 检索创建时间/更新时间戳?

objective-c - 2 应该相等的 NSDates 不是吗?

iphone - xamarin studio 在发布版本的设置中有一个调试主机选项吗?

ios - 我是否必须做一些特别的事情才能让 TestFlight 构建使用我的通知扩展目标?它被忽略了

ios - 在 UICollectionViewController 中按下 UICollectionViewCell 后无响应

iphone - 无法显示异步加载的纹理

ios - Xcode 7.3 : "Ambiguous expansion of macro" when re-defining macro in prefix file

ios - 为什么我们在iOS中使用出队可重用关键字

html - 如何解决 iPhone 的 Bootstrap 复选框布局问题