0

我尝试在 imageview 中加载动态图像,在 label 中加载文本,它在模拟器和 ios 设备中都可以正常工作。(见下面的代码)

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
      {
          ImageCell  *cell = (ImageCell *)[self.TestTable dequeueReusableCellWithIdentifier:@"ImageCell"];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        if (cell == nil) {
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ImageCell" owner:self options:nil];
            cell = [topLevelObjects objectAtIndex:0];
        }
    }
    else
    {
        if (cell == nil)
        {

            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ImageCell" owner:self options:nil];
            cell = [topLevelObjects objectAtIndex:0];
        }
    }

cell.textlabels.text=@"Cable and Hose Carriers";

cell.ProductsImages.image = [UIImage imageNamed:@"cool.jpg"];



return cell;
} 

但是,如果我尝试在自定义 tableview 单元格中的 uitextview 中加载数据,tableview 在 ios 设备中滚动不流畅(口吃),但在模拟器中工作正常。请建议我做得更好。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
      {
          ImageCell  *cell = (ImageCell *)[self.TestTable dequeueReusableCellWithIdentifier:@"ImageCell"];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        if (cell == nil) {
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ImageCell" owner:self options:nil];
            cell = [topLevelObjects objectAtIndex:0];
        }
    }
    else
    {
        if (cell == nil)
        {

            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ImageCell" owner:self options:nil];
            cell = [topLevelObjects objectAtIndex:0];
        }
    }
cell.ProductsDetailsTextView.delegate = self;
cell.ProductsDetailsTextView.text=[Descriptions objectAtIndex:indexpath.row];

return cell;
} 
4

1 回答 1

3

您正在尝试在主线程上做所有事情。由于动态加载数据,您的主线程开始阻塞,这就是 tableview 滚动不顺畅的原因。尝试在不同的队列中编写代码

// call background queue for dynamic loading of data
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{


   // load your dynamic data here

    // call main queue here
    dispatch_async(dispatch_get_main_queue(), ^{
     // after loading data in background. use your downloaded data here.  
    });
});

而已。

于 2013-08-22T10:21:53.167 回答