2

我在 UITableViewController 中使用了如下多项选择。这是 UIAlertView 的委托方法,其中有 UIAlertView 包含 Table。

现在如何将特定选定的 indexPath.row 添加到我的数组中,如果有人取消选中它,则将其删除。

- (void)tableAlert:(SBTableAlert *)tableAlert didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSLog(@"MY INDEX PATH IS %@", indexPath);


if (tableAlert.type == SBTableAlertTypeMultipleSelct) {
    UITableViewCell *cell = [tableAlert.tableView cellForRowAtIndexPath:indexPath];
    if (cell.accessoryType == UITableViewCellAccessoryNone)
        [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
    else
        [cell setAccessoryType:UITableViewCellAccessoryNone];

    [tableAlert.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
4

1 回答 1

0

我很想创建一个用于 tableView 的项目的字典。然后为字典中的每个对象都有一个“选定的”布尔属性。然后,您可以简单地将其设置为 true 或 false,并[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];在您的警报视图被点击时使用。如果您需要知道哪些对象的行被选中,您还可以枚举。

于 2013-10-02T13:36:41.420 回答