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

编程入门 行业动态 更新时间:2024-10-28 11:23:19
本文介绍了触摸时更改表格单元格的 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:关键词]

本文发布于:2023-04-29 04:09:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1184032.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元格   表格   UIImage

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!