2014-10-17 232 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