2017-04-19 30 views
0

我已經嘗試了所有的方法,如運行在主線程等.... 但他們都沒有工作.. 我的表有超過500行,其中包含圖像音頻以及文本.. 每次重新載入表時至少需要5到10秒的時間,並且ui是凍結的。 請幫我在這...表重新加載需要太多的時間來更新單元

+1

請顯示一些代碼,以便我們能夠確定在你犯錯的地方。 –

+0

感謝您的回覆....更多的時間在heightForRowAtIndexPath同時計算單個行的高度...當我重新加載表時它需要更多的時間500行高度和不同的高度... –

+0

請發表一些代碼。 –

回答

1

u可以使用NSOperational隊列:

NSOperationQueue *que = [[NSOperationQueue alloc]init]; 

     [que addOperationWithBlock:^{ 

       [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 


     //u can assign all the table view values and content here 

     // it will not pause the data u can scroll immediately    
      }]; 

     }]; 

溶液2:

呼叫烏爾數據:

dispatch_async(dispatch_get_main_queue(), ^{ 
//call ur data methods or web services methods in side this block 
    }); 

分配表中的視圖中的數據:

NSOperationQueue *que = [[NSOperationQueue alloc]init]; 

      [que addOperationWithBlock:^{ 

        [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 


      //u can assign all the table view values and content here 

      // it will not pause the data u can scroll immediately    
       }]; 

      }]; 
+0

感謝您的回覆....更多的時間在heightForRowAtIndexPath同時計算單個行的高度...當我重新加載表時,它需要更多的時間500行高度和不同的高度...你的方法將正常工作。 。但問題是它需要3秒的時間來更新表後高度計算 –

+0

RU從服務器獲取數據填充表或本地內存 –

+0

從本地數據庫/內存獲取數據 –

0

你需要使用GCD此:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), 
        // do backgroud work 
        ^{ 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      // do UI work like 
      // label.text = "" 
      // or many others 
     }); 
    }); 
0

除了@KKRocks答案,在大多數情況下,沒有必要填充表的所有500行,你可以只填充50個,並在滾動到底部時動態添加單元格。

0

認爲你正在使用的電池創作

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

數據源的方法以及數據的設置。我的建議是僅將數據源方法用於單元格創建。然後使用

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 

代表設置數據的方法。使用此示例代碼

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

{

MyWishListTableViewCell *cell = [tableView 
dequeueReusableCellWithIdentifier:@"Order_Cell_Indntifire" 
forIndexPath:indexPath]; 
return cell; 
} 

}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 

{

if ([cell isKindOfClass:[MyWishListTableViewCell class]]) 
{ 
MyWishListModel* data = [_myWishListArray objectAtIndex:indexPath.row]; 
MyWishListTableViewCell *cell1 = (MyWishListTableViewCell*)cell; 
[cell1 setUpData:data]; 
} 

}

相關問題