2011-04-22 52 views
0

我想保存保存UITableViewAccesoryType状态我有两个部分中的两个单元格。本部分(顶部)有两个选项http://cl.ly/6DVQ bit.ly或j.mp. 下面的两个单元格是用户名和whatnot。我在这里尝试了这个How to preserve the index path value in the table view in iPhone?,但它用于保存所有单元格的状态,并且不允许我单击一个单元格并取消选中其他单元格。我试图将其保存到NSUserDefaults,以便我可以拉起选定的单元格并在不同的视图控制器中使用它。任何人对我如何完成任何想法?像往常一样,示例代码和教程是有帮助的。UITableViewCell附件类型

感谢

+0

嘛,有一半的问题都没有得到回答,但。我想要做的是保存accessoryCheckmark,并选择哪个单元格到NSUserDefaults,当视图再次加载时,它将附件类型设置为单元格。 – Frankrockz 2011-04-22 23:57:09

回答

0

好了,看完您的评论后,这里是我会怎么做:

// In the didSelectCell: method 
if (indexPath.section == 0) { 
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:indexPath.row] forKey:@"ShortingService"]; 
} 

// In "cellForRowAtIndexPath:" 
if (indexPath.section == 0) { 
    int selectedRow = [[[NSUserDefaults standardUserDefaults] objectForKey:@"ShortingService"] intValue]; 
    if (indexPath.row == selectedRow) 
     cell.accessoryType = UITableViewCellAccessoryTypeCheckmark; 
} 
+0

完美工作:)谢谢 – Frankrockz 2011-04-23 02:53:08