我在下面有这个设置,但当我触摸表格单元格时,我收到警报,所以我知道正在调用该方法,但单元格左侧的图像没有变化。这就是我的代码: 在视图控制器中,我有以下两种方法:
-(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
}
需要我能得到的所有帮助,谢谢!
答案 0 :(得分: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"];
}
答案 1 :(得分:1)
您忘记更改imageView:
cellImage = [UIImage imageNamed:@"checkboxfull.png"];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.imageView.image = cellImage;