2012-02-20 30 views
3

我在下面有这个设置,但是当我触摸表格单元格时,我得到了警告,所以我知道该方法正在被调用,但单元格左侧的图像没有更改。这是我的代码如下所示: 在视图控制器我有这2种方法:更改触摸表格单元格的UIImage

​​

cellImage在.H声明,我在此.M合成它,以及

正下方上面的方法,我有这样的一个(我改变图像的底部!

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; 
{ 
    NSString *cellselected = [NSString stringWithFormat:@"cell selected %@", [tabledata objectAtIndex:indexPath.row]]; 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:cellselected delegate:self cancelButtonTitle:@"close" otherButtonTitles:nil]; 

    [alert show]; 
    //------------------------------------------------------------------------------start 
    cellImage = [UIImage imageNamed:@"checkboxfull.png"]; 
    //----------------------------------------------------------------------------end 

} 

需要的所有帮助我能得到,感谢

+0

你试图引用直接的UIImageView的形象? “cell.imageView.image = [UIImage imageNamed:@”checkboxfull.png“];” 我不知道,但也许“cell.imageView.image = cellImage;”需要UIImage的副本,因为它仍然没有加载到内存中。 – Markus 2012-02-20 17:01:20

回答

3
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; 
{ 

    NSString *cellselected = [NSString stringWithFormat:@"cell selected %@", [tabledata objectAtIndex:indexPath.row]]; 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:cellselected delegate:self cancelButtonTitle:@"close" otherButtonTitles:nil]; 

    [alert show]; 
    [alert release]; 

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    cell.imageView.image = [UIImage imageNamed:@"checkboxfull.png"]; 
} 
+0

太棒了!非常感谢,哈哈!我很高兴。现在我将如何再次点击将其更改回其他图像? – user1191343 2012-02-20 17:11:36

+0

检查'if([cell.imageView.image isEqual:[UIImage imageNamed:@“checkboxfull.png”]])'改变为其他人......其他改为 – Shubhank 2012-02-20 17:13:34

+0

男人,非常感谢。我感觉很棒,有这个工作,非常感谢。 – user1191343 2012-02-20 17:33:24

1

你忘了改变的ImageView:

cellImage = [UIImage imageNamed:@"checkboxfull.png"]; 
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
cell.imageView.image = cellImage; 
+0

谢谢,你们都给出了相同的答案。 – user1191343 2012-02-20 17:12:18

相关问题