2014-10-17 127 views
0

我有在UiTableView上加载的问题我有延迟4秒在4s iphone和9sec 4 iphone。我使用异步下载图像,速度非常快。缓慢加载UiTableView

-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath  *)indexPath{ 
    static NSString *CellIdentifier = @"item2"; 
    NSLog(@"loading"); 
    MenuCell *cells = [tableView dequeueReusableCellWithIdentifier:CellIdentifier  forIndexPath:indexPath]; 
    NSLog(@"1"); 
    cells.Title.text=[name objectAtIndex:indexPath.row]; 
    [cells.Title setTextColor:[UIColor colorWithRed:(red/255.f) green:(green/255.f) blue:(blue/255.f) alpha:1.0f]]; 
    NSLog(@"2"); 

    NSLog(@"3"); 
    [cells.Image setImageWithURL:[NSURL URLWithString:[page_icon objectAtIndex:indexPath.row]] placeholderImage:[UIImage imageNamed:@"clickgatemikro.png"]]; 
    NSLog(@"4"); 
    return cells; 
} 

而且我的输出:(4秒延时):

2014-10-17 17:28:19.504 Accounting[501:53015] numberOfRowsInSection TABLE COUNT : 12 
2014-10-17 17:28:19.513 Accounting[501:53015] numberOfRowsInSection TABLE COUNT : 12 
2014-10-17 17:28:19.515 Accounting[501:53015] loading 
2014-10-17 17:28:23.609 Accounting[501:53015] 1 
2014-10-17 17:28:23.611 Accounting[501:53015] 2 
2014-10-17 17:28:23.612 Accounting[501:53015] 3 
2014-10-17 17:28:23.624 Accounting[501:53015] 4 
2014-10-17 17:28:23.625 Accounting[501:53015] loading 
2014-10-17 17:28:23.635 Accounting[501:53015] 1 
2014-10-17 17:28:23.635 Accounting[501:53015] 2 
2014-10-17 17:28:23.636 Accounting[501:53015] 3 
2014-10-17 17:28:23.638 Accounting[501:53015] 4 
2014-10-17 17:28:23.639 Accounting[501:53015] loading 
2014-10-17 17:28:23.645 Accounting[501:53015] 1 
2014-10-17 17:28:23.651 Accounting[501:53015] 2 
2014-10-17 17:28:23.652 Accounting[501:53015] 3 
2014-10-17 17:28:23.654 Accounting[501:53015] 4 
2014-10-17 17:28:23.698 Accounting[501:53015] FINISH 

----------更新-------------

这里是我的代码,我使用的plist加载在我Mutablearray我DATAS然后我打电话reloadData

- (void)viewDidLoad { 
[super viewDidLoad]; 
[self initVariables]; 
[self initplist]; 
self.mytableview.delegate = self; 
self.mytableview.dataSource = self; 

name = [plistDict objectForKey:@"title"]; 
image= [plistDict objectForKey:@"image"]; 


[self.mytableview reloadData]; 

} 

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
NSLog(@" numberOfRowsInSection TABLE COUNT : %lu",(unsigned long)[name count]); 
return [name count]; 
} 


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
return 1; 
} 
+0

调用'reloadData'后会发生这个问题吗?显示你在哪里调用'reloadData'。确保它在主线程上完成。你的'cellForRowAtIndexPath'没有问题。 – rmaddy 2014-10-17 14:42:50

回答

0

当你想从一个URL显示图像,使用异步的,因为它的阻止页面DRAWIN g在同步模式下,在图像dl中使用占位符并将占位符替换为图像。

+1

OP正在使用图像的异步加载。注意日志输出。细胞加载速度非常快。 – rmaddy 2014-10-17 14:43:32

+0

2014-10-17 17:28:19.515 loading - > 2014-10-17 17:28:23.609 1(4秒延迟)问题是初始化我认为 – Cliff 2014-10-17 14:48:10

+0

@Cliff我刚刚注意到了这一点。看起来第一个需要从xib或storyboard加载单元会造成巨大的延迟。 – rmaddy 2014-10-17 14:50:54