如何在uitableviewcell上显示UIImage

时间:2013-05-01 08:28:04

标签: iphone ios objective-c uitableview

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

1 个答案:

答案 0 :(得分:1)

我假设在你的tableview中,每个单元格代表一个数组的模型实例。切换开关时更新模型会不会更好?:

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

然后重新加载tableview单元格

-(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;
}
相关问题