Ios 为什么tableview要花这么多时间更新?

Ios 为什么tableview要花这么多时间更新?,ios,objective-c,uitableview,core-data,Ios,Objective C,Uitableview,Core Data,我目前有一个UITableView,它向我显示了一个从facebook派生的特定事件的人员列表。 我目前在获取和插入核心数据方面没有任何问题,但更新tableview所需的时间大约为12秒 用户首先选择一个事件 然后进入编辑屏幕 将事件类型更改为周年纪念(引出序号) 我回家的路也一样,但问题就在这里, 我的tableview可能在12秒后更新为周年纪念类型的事件。为什么更新tableview会有这么多延迟 cellForRowAtIndexPath - (UITableViewCell *)ta

我目前有一个UITableView,它向我显示了一个从facebook派生的特定事件的人员列表。 我目前在获取和插入核心数据方面没有任何问题,但更新tableview所需的时间大约为12秒

用户首先选择一个事件

然后进入编辑屏幕

将事件类型更改为周年纪念(引出序号)

我回家的路也一样,但问题就在这里, 我的tableview可能在12秒后更新为周年纪念类型的事件。为什么更新tableview会有这么多延迟

cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
static NSString *CellIdentifier = @"EventCell";

//testing


EventCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
PersonEvent *currentEvent = [self.eventsArray objectAtIndex:indexPath.row];

[cell configureForEvent:currentEvent];
//  NSLog(@"Event date is %@",[currentEvent.eventDate description]);
// NSLog(@"Time interval %f",[currentEvent timeDifference]);
//[self configureCell:cell atIndexPath:indexPath];
return cell;

}
配置ForEvent

-(void)configureForEvent:(PersonEvent*)theEvent
 {

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);
dispatch_async(queue, ^{
    //performing async operation her

    dispatch_sync(dispatch_get_main_queue(), ^{

        personLabel.text = theEvent.name;
        dateLabel.text = [theEvent getFriendlyDate];
        //  NSInteger theAge = [theEvent getAge];
        if (theEvent.hasAge) {
            //  NSLog(@"Have to load the age as well for %@",theEvent.name);
            ageLabel.text = [NSString stringWithFormat:@"%d yrs",[theEvent getAge] ];
        }
        else{
            ageLabel.text = @"";
        }

        //ageLabel.text = [NSString stringWithFormat:@"%d yrs",[theEvent getAge] ];
        reminderImage.image = [theEvent.theReminders count] == 0?[UIImage imageNamed:@"reminder.png"]:nil;
        // Have to configure event type image based on the event type..
        //NSLog(@"Event image %@",[eventTypeImagesArray objectAtIndex:theEvent.eventType]);
        eventTypeImage.image = [UIImage imageNamed:[eventTypeImagesArray objectAtIndex:theEvent.eventType]];;

        // Update UI
        // Example:
        // self.myLabel.text = result;
    });
});



}
loadAllEventz方法,该方法在initWithNibName上调用

-(void)loadAllEventz
{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"PersonEvent" inManagedObjectContext:appDelegate.managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]initWithKey:@"eventDate" ascending:YES];
[fetchRequest setSortDescriptors:@[sortDescriptor]];

NSError *error;
    allEventsArray = [appDelegate.managedObjectContext executeFetchRequest:fetchRequest error:&error];
NSLog(@"%@",allEventsArray); 
//  [appDelegate.managedObjectContext executeFetchRequestAsynchronously:fetchRequest delegate:self];


 }

PersonEvent类是一个NSManagedObject子类,tableview的性能取决于数据源方法

您在代码中实现了GCD,但运行是在主线程中完成的


beign slow的问题是图像加载速度慢。在插入图像时使用GCD,或者使用Asynchimageview/AFnetworking Extension、SDWebimageView等类

也许我认为这一切都错了,但当事件更新时,是否将更新发送到web服务,然后在返回到
表视图时从web服务检索?如果是这样,那似乎效率很低。既然您知道已更改的数据,为什么不使用
委托
方法(或
展开序列
)将更新发送回
表视图
,然后在后台将更新发送到web服务?除非您需要尚未获得的信息,否则就没有理由再次轮询web服务。从您的流来看,似乎您正在重新轮询web服务以获得您已经知道的更新


还有,在图片上。它看起来确实像一个小静态组的图像,你正在使用的提醒。为什么不下载它们一次(在应用程序初始加载时),然后使用本地存储的,这样您就不会每次都获取它们。

UITableView工作得很快。问题不在tableView中。您最好测量“执行异步操作”的运行时间。

在configureForEvent:method中使用GCD的任何特定原因?如果您可以将代码发布到填充/获取数据源的位置,这也会很有帮助。我特意这样做,以使其加速。。这没有帮助GCD块的异步部分为空,您正在主队列上执行所有操作。因此,它实际上没有帮助。我建议您删除它并保持函数的简单性。至于性能部分,这取决于您如何填充数据源。当您的用户更新事件类型时,您执行的核心数据操作是什么?更新完成后,如何重新填充表视图数据源?当我编辑事件并更改名称时,更新也需要12秒,我想这与图像加载无关不,我没有向webservice发送任何更新,基本上我是使用webservice检索数据并将其插入核心数据,然后相应地检索它,但它仍然在减速,我不明白为什么