[英]Table reload taking too much time to update the cells
我已經嘗試了所有方法,例如在主線程中運行等。。。但是它們都不起作用。.我的表有500多個行,其中包含圖像音頻和文本。 5至10秒的時間,用戶界面凍結。 請幫我解決這個問題...
您可以使用NSOperational Queue:
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
}];
}];
您需要為此使用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
});
});
除了@KKRocks答案外,在大多數情況下,不需要填充所有500行的表,您只能填充50行,並在滾動到底部時動態添加單元格。
認為您正在使用
- (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];
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.