如何在uitableviewcell上显示UIImage

我有UITableview显示基于UISwitch状态的UIImage 。 我将开关状态存储在NSMutableArray 。 我能够只显示两个图像,如果我试图显示超过两个不显示。 如果我closures两个较早的UISwitch状态中的任何一个。 新的开关状态(我试图显示在前面)将显示,也只有一个。

我假设在你的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; }