如何在 uitableviewcell 上显示 UIImage [英] How to display UIImage on uitableviewcell

查看:29
本文介绍了如何在 uitableviewcell 上显示 UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 UITableview 在这里我根据 UISwitch 状态显示一个 UIImage.我将开关状态存储在 NSMutableArray 中.如果我尝试显示两个以上不显示的图像,我只能显示两个图像.如果我关闭前两个 UISwitch 状态中的任何一个.新的开关状态(我之前试图显示)将只显示一个.

I have UITableview where I display an UIImage based on UISwitch state. I am storing the switch state in NSMutableArray. I am able to display only two images if i try to display more than two its not displaying. If I switch OFF any one of the two earlier UISwitch states. The new switch state (which i was trying to display earlier) will get displayed that too only one.

推荐答案

我假设在您的 tableview 中,每个单元格代表一个来自数组的模型实例.切换开关时更新模型不是更好吗?:

I am assuming in your tableview each cell represents an instance of a model from an array. Would it not be better to update the model when the switch is toggled?:

...
MyObject theObject= [myObjects objectAtIndex:index];
theObject.switchState = TRUE;
[self.tableView reloadData];
...

然后重新加载tableview单元

and then reload the tableview cells

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"cellidentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];


     MyObject *thisObject = [myObjects objectAtIndex:indexPath.row];

     if(thisObject.switchState) {
          ... configure cell accordingly
     }

     return cell;
}

这篇关于如何在 uitableviewcell 上显示 UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆