-2

我有UITableview我显示UIImage基于UISwitch状态的地方。我将开关状态存储在NSMutableArray. 如果我尝试显示两个以上不显示的图像,我只能显示两个图像。如果我关闭前两种UISwitch状态中的任何一种。新的开关状态(我之前试图显示)也只会显示一个。

4

1 回答 1

1

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

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

然后重新加载表格视图单元格

-(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;
}
于 2013-05-01T09:33:12.897 回答