触摸时更改表格单元格的UIImage

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

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath; { UITableViewCell *cell = nil; cell = [tableView dequeueReusableCellWithIdentifier:@"homeworkcell"]; if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"homeworkcell"]; } cell.textLabel.text = [tabledata objectAtIndex:indexPath.row]; //static NSString *CellIdentifier = @"Cell"; /* if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; }*/ // Configure the cell. //----------------------------------START----------------------Set image of cell---- cellImage = [UIImage imageNamed:@"checkboxblank.png"]; cell.imageView.image = cellImage; //-------------------------------END---------------------------end set image of cell-- return cell; } 

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 } 

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

 - (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"]; } 

您忘记更改imageView:

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