【发布时间】:2011-11-21 19:52:54
【问题描述】:
所以我正在开发一个应用程序,其中包含一个表格视图,其中包含单元格中的图像。我从一个 URL 下载所有这些图像并将它们存储在一个数组中。我需要异步加载这些图像,所以我决定使用 NSURLConnectionDataDelegate。我试过这段代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSUInteger row = [indexPath row];
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[URLsArray objectAtIndex:row]]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
receicedData = [[NSMutableData alloc] init];
} else {
NSLog(@"Failed.");
}
return cell;
}
但它不起作用。而且我不知道该写什么:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
将图像设置为单元格中的图像视图。有人可以帮忙吗?
【问题讨论】:
标签: ios uitableview nsurlconnection