objective-c - 触摸时更改表格单元格的 UIImage

标签 objective-c ios uiimage

我在下面有这个设置,但是当我触摸表格单元格时,我收到了警报,所以我知道正在调用该方法,但单元格左侧的图像没有改变。这是我的代码的样子: 在 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/

相关文章:

iphone - XMPP 框架接收的最大消息数

ios UIImageRenderingModeAlwaysTemplate 不会忽略不透明度

swift +UIImageView : switch between two animation frame sequences?

objective-c - 在 WebKit 中,如何获取资源的内容?

ios - 无法将特定的CGColor应用于CGContextSetFillColor

ios - 从 Objective-c 中的 .bundle 加载 png 时出错

iphone - iOS - 如何使用 mkmapview 作为位置选择器

ios - Apple Watch "No such module ' Alamofire'”

ios - 如何在 UIView 表格单元格中制作幻灯片

ios - 如何使用 swift 将图像从 Images.xcassets 加载到 UIImage