【发布时间】:2010-09-09 18:15:01
【问题描述】:
我已将图像放入我的 tableview 单元格中,该图像位于某个 URL 中。 我的问题是,当我的 tableView 已经显示数据时, 然后上下滚动表格视图,它需要一些时间或延迟才能对滚动做出反应..
我发现问题出在 URL 中的图像中,我还需要在 tableview 单元格中显示每个图像。 知道如何解决吗?还是要优化?
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell
NSUInteger row = [indexPath row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
NSArray *arrLocal = [m_list objectAtIndex:row];
if ([arrLocal count] > 0) {
cell.textLabel.text = [arrLocal objectAtIndex:2];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
cell.detailTextLabel.text = [arrLocal objectAtIndex:3];
cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
//sample url of the image: http://www.mysite.com/images/DealExtreme/2657_1_small.jpg
NSString *strTemp = [[NSString alloc] initWithString:@"http://www.mysite.com/"];
NSString *urlString = [strTemp stringByAppendingString: [arrLocal objectAtIndex:1]];
NSURL *url = [NSURL URLWithString:urlString];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
cell.imageView.image = image;
[strTemp release];
}
return cell;
}
【问题讨论】:
标签: iphone uitableview