我有一些代碼可以改變在分組表格視圖中完美工作的單元的背景圖像。但是,並不是一張普通的表格。有誰知道爲什麼這些行爲有所不同?我想要做的就是給表格單元格添加一個背景圖像(普通)iPhone:普通表問題。沒有出現單元背景圖像
這對分組表格視圖完美。我是否需要自定義單元格才能使用普通視圖?
感謝西蒙
-(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];
}
}
這麼簡單,完全工作 – Burf2000 2010-09-23 13:32:48