如何显示在单元格中的形象呢?
-
19-09-2019 - |
题
我是新iphone development.I想在每个cell.I显示图像时遇到只在array.please的图像的URL帮我out.Thanks。
解决方案
//put this code in cellForRowAtIndexPath.... I'm assuming you have an array of url's that point to images
id urlPath = [yourArray objectAtIndex:indexOfImage];
NSURL *url = [NSURL URLWithString:urlPath];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//insert an image into your cell
cell.imageView = image;
有可能是这样做更有效的方式,但它的上手定制你的tableview细胞一个体面的方式。 ImageView的是UITableViewCell类,的许多特性中的一个。
进一步阅读.... 的UITableViewCell类参考
其他提示
您应该看看这个苹果的示例代码,它是伟大的,显示了如何实现你所需要的以及其他有用的东西: 高级表视图细胞
不隶属于 StackOverflow