我有一个 UITableView,它从服务器下载其表格视图单元格图像。
我观察到表格滚动非常慢。
我认为这可能是由于下载造成的,但我意识到下载完成后表格仍然滚动缓慢,并且图像图标大小非常小。
代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
btnBack.hidden = FALSE;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
///////////////////// Cell other accessories /////////////////////
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.backgroundColor = [UIColor clearColor];
// cell.backgroundView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"list_1.jpg"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0]];
// cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"list_2.jpg"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0]];
///////////////////// Cell Title /////////////////////
cell.textLabel.font = [UIFont fontWithName:@"Noteworthy" size:17.0];
cell.textLabel.font = [UIFont boldSystemFontOfSize:17.0];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.highlightedTextColor = [UIColor blackColor];
}
///////////////////// Cell Title /////////////////////
cell.textLabel.text = [NSString stringWithFormat:@" %@", [test.arrTitle objectAtIndex:indexPath.row]];
///////////////////// Cell Image /////////////////////
NSString *Path;
Path = [NSString stringWithFormat:@"http://%@",[test.arrImages objectAtIndex:indexPath.row]];
NSLog(@"image-->%@",[test.arrImages objectAtIndex:indexPath.row]);
NSString *strImage = Path;
NSURL *url4Image = [NSURL URLWithString:strImage];
NSData *data = [NSData dataWithContentsOfURL:url4Image];
image =[[UIImage alloc] initWithData:data];
cell.imageView.image =image;
[image release];
return cell;
}
你应该考虑使用NSOperationQueue http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/NSOperationQueue_class/Reference/Reference.html处理图像和自定义 uitableviewcell 的延迟加载。
Google for tweetie 自定义 tableviewcell
这应该会让你走上正确的方向。
Apple 有一个用于下载 tableView 中图像的示例项目:惰性表图像 http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009394-Intro-DontLinkElementID_2
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)