【发布时间】:2014-03-11 14:07:17
【问题描述】:
我有一个 iPhone 应用程序,我在其中从一个数组异步加载图像,在 cellforrowatindexpath 中使用它,
` - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
sCell *cell = (sCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[sCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSMutableDictionary *dicttable=[sarray objectAtIndex:indexPath.section];
NSString *icon= [dicttable objectForKey:@"thumb_image"];
cell.image.image = [UIImage imageNamed:@"thumbnail-default.png"];
if(icon.length!=0)
{
if(![[ImageCache sharedImageCache] hasImageWithKey:icon])
{ cell.image.image = [UIImage imageNamed:@"thumbnail-default.png"];
NSArray *myArray = [NSArray arrayWithObjects:cell.image,icon,@"thumbnail-default.png",[NSNumber numberWithBool:NO],nil];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate performSelectorInBackground:@selector(updateImageViewInBackground:) withObject:myArray];
}
else
{
cell.image.image = [[ImageCache sharedImageCache] getImagefromCacheOrUrl:icon];
}
}`
一切正常,因为我启用了分页,所以我需要调用请求来加载下一组值,就像这样
`- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section==[sarray count]-1)
{
[self performSelectorInBackground:@selector(loadingfeedcntents:) withObject:count];
}
}`
但这里的问题是,当我滚动表格视图时,错误的图像被分配给自定义单元格中的图像视图,有人可以帮助我吗?
【问题讨论】:
-
听起来问题在于重用 tableview 中的单元格,您能否将代码粘贴到您创建并返回 tableview 单元格的位置。
-
@Preson 你能检查我编辑的问题吗...
-
请在您的代码中添加
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath部分。willDisplayCell在屏幕上渲染单元格之前调用,内容在cellForRowAtIndexPath方法中设置。 -
@Preson 那是第一个..
标签: ios iphone objective-c ipad uitableview