[英]iPhone : Plain table issue. Cell background image not appearing
I have a some code that changes the background image of a cell which works perfectly in a grouped table view. 我有一些代码可以更改单元格的背景图像,该图像在分组表视图中可以完美运行。 However, does not in a plain table.
但是,不在普通表中。 Does anyone know why these behave differently?
有谁知道为什么它们表现不同? All I want to do is add a background image to a table cell (plain)
我要做的就是将背景图像添加到表格单元格(纯文本)
This works perfectly on a grouped table view . 这在分组表视图中完美工作 。 Do I need a custom cell for it to work with a plain view?
我是否需要一个自定义单元格才能使用纯视图?
Thanks Simon 谢谢西蒙
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
UniversalAppAppDelegate *appDelegate = (UniversalAppAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *rowData;
// Check see if section Data is populated
if (self.sectionData == nil) {
rowData = [(NSDictionary *)[tableData objectAtIndex:indexPath.section] objectForKey:@"SectionItems"];
} else {
rowData = [(NSDictionary *)[sectionData objectAtIndex:indexPath.section] objectForKey:@"SectionItems"]; //[self.sectionData objectAtIndex:indexPath.section];
}
NSDictionary *cellDetails = [rowData objectAtIndex:indexPath.row];
// Clear any previous imageview
UIView *view = [cell.backgroundView viewWithTag:99];
if (view != nil)
[view removeFromSuperview];
// Add a new imageview
NSString *filename = [cellDetails objectForKey:@"TableItemFullImage"];
if (filename.length > 0) {
UIImageView *cellImageView = [[UIImageView alloc] initWithImage:[appDelegate imageForImageID:[cellDetails objectForKey:@"TableItemFullImage"] imageExtension:[cellDetails objectForKey:@"TableItemFullImageType"]]];
cellImageView.tag = 99;
CGRect newFrame = cell.backgroundView.bounds;
cellImageView.frame = newFrame;
[cell.backgroundView addSubview:cellImageView];
[cellImageView release];
}
} }
You're overcomplicating things. 您太复杂了。
UIImage * image = [appDelegate ...];
cell.backgroundView = [[[UIImageView alloc] initWithImage:image] autorelease];
I suspect that in the plain table view, the indexPath.section will not return you correct data. 我怀疑在普通表视图中,indexPath.section不会返回正确的数据。 So these few lines of codes can give you a nil rowData.
因此,这几行代码可以为您提供零的rowData。 Double check for that
仔细检查
// Check see if section Data is populated
if (self.sectionData == nil) {
rowData = [(NSDictionary *)[tableData objectAtIndex:indexPath.section] objectForKey:@"SectionItems"];
} else {
rowData = [(NSDictionary *)[sectionData objectAtIndex:indexPath.section] objectForKey:@"SectionItems"]; //[self.sectionData objectAtIndex:indexPath.section];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.