本文介绍了触摸时更改表格单元格的 UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我在下面有这个设置,但是当我触摸表格单元格时,我收到警报,所以我知道正在调用该方法,但单元格左侧的图像没有改变.这是我的代码的样子:在视图控制器中,我有这两种方法:
I have this setting below, but when I touch the table cell, I get the alert, so I know the method is being called but the image on the left of the cell isn't changing. This is what my code looks like: In the view controller I have these 2 methods:
-(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 中合成了它
cellImage is declared in the .h and I synthesized it as well in this .m
在上述方法的正下方,我有这个(我更改了底部的图像:
right below the above method, I have this one(i change the image at the bottom:
- (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
}
需要我能得到的所有帮助,谢谢!
Need all the help I can get, thanks!
推荐答案
- (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"];
}
这篇关于触摸时更改表格单元格的 UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论