2013-05-01 77 views
-2

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

+1

缩进你的代码yaar ... – 2013-05-01 08:30:34

+0

现在怎么样anoop? – raptor 2013-05-01 08:58:58

+0

我等了5分钟,然后我重新格式化了...现在这看起来不错:) – 2013-05-01 08:59:54

回答

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; 
} 
+0

@Marcel ...我已经更新了代码..图像出现在两个单元格,如果我尝试打开更多的单元格图像没有出现在那些单元格中 – raptor 2013-05-02 10:39:14

+0

你能发布你的新代码吗? – Marcel 2013-05-02 11:17:45

+0

我已更新代码 – raptor 2013-05-03 16:23:41