UITableViewCell Accesory Type

时间:2011-04-22 23:38:15

标签: iphone uitableview

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

由于

1 个答案:

答案 0 :(得分: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;
}