我在下面有这个设置,但是当我触摸表格单元格时,我收到了警报,所以我知道正在调用该方法,但单元格左侧的图像没有改变。这是我的代码的样子: 在 View Controller 中我有这两种方法:
-(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"];
}
关于objective-c - 触摸时更改表格单元格的 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9365027/