2017-04-19 28 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]; 
} 

}

相关问题