我尝试在imageview中加载动态图像,在标签中加载文本,它在模拟器和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;
}
答案 0 :(得分: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.
});
});
多数民众赞成。