【发布时间】:2014-01-07 09:23:08
【问题描述】:
我有UITableView,我想在viewDidLoad 方法中在第一个单元格上添加背景图像,在第一个单元格上添加图像后,当用户选择任何其他行时,我想隐藏我的背景图像。
可以吗?
请提前帮助和感谢。
编辑:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath{
if(indexPath.row==0){
cell.backgroundView = [ [UIImageView alloc] initWithImage:[[UIImage imageNamed:@"active-tab.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
flag=true;
NSLog(@"willDisplayCell");
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (flag==true) {
cell.backgroundView = nil; //How to get `cell` here ?
//How to remove BGImage from first cell ???
}
}
【问题讨论】:
-
你应该包含更多的代码,让人们更容易看到你是怎么做的,而不是猜测
-
不要忘记标记最佳答案并为对您有帮助的答案投票。面临同样问题的人会想知道是什么解决了您的问题,而那些花时间回答您问题的人应该获得声誉积分
-
我删除了我的反对票,纯粹是因为添加了有助于识别问题的代码。然而,我确实觉得这个问题仍然有点缺乏,下次我会鼓励你付出更多的努力,因为其他人在看到这个问题时更有可能关闭一个问题
标签: ios iphone uitableview uiimage