我在設置UIImageView或UIView對iPhone上分組表格的單元格時遇到問題。將UIImageView或UIView添加到分組表格的單元格
爲了這個,我用這個代碼
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
NSArray *listData =[self.tableContents objectForKey:[self.sotreKeys objectAtIndex:[indexPath section]]];
UITableViewCell * cell = [tableView
dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier] autorelease];
}
if(indexPath.section == 1 && indexPath.row ==1)
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(240, 14, 40, 40)];
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"Back.png",nil]];
[cell.contentView addSubview:imageView];
[imageView release];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
return cell;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
但它不是放置在細胞。當我選擇只顯示那一行的行時,會出現什麼問題?
有沒有人有任何想法是什麼問題。我認爲圖像被細胞覆蓋。
在此先感謝
仔細檢查 「Back.png」 確實存在於您的項目資源 –
此外,使用[ImageView的setBackgroundColor:[的UIColor redColor];這實際上將幫助你看看莫名其妙圖像是不可見由於細胞/表背景顏色 –
@joe是你有任何想法在添加圖像onthe細胞我在我的應用程序分組表視圖是問題。 – Ajay