selectRowAtIndexPath仅在allowsMultipleSelection为YES时有效

Bar*_*uch 3 iphone uitableview ios ios5

我有一个UITableViewController动态填充,取决于用户以前的选择.在某些情况下,用户应该能够在表中选择多行,但在其他情况下,他不应该.我想在任何一种情况下自动选择第一行,但我发现它只在我有时才有用allowsMultipleSelection = YES.

在此期间调用以下代码 -(void)viewDidLoad

switch(self.field)
{
    case people:
       self.options = (NSArray *)[data objectForKey:@"People"];
       self.tableView.allowsMultipleSelection = YES;
       enter code here break;
    case place:
        self.options = (NSArray *)[data objectForKey:@"Places"];
        self.tableView.allowsMultipleSelection = NO;
        break;
    case reason:
        self.options = (NSArray *)[data objectForKey:@"Reasons"];
        self.tableView.allowsMultipleSelection = NO;
        break;
}

[self.tableView reloadData];
NSIndexPath *zeroPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView selectRowAtIndexPath:zeroPath animated:NO scrollPosition:UITableViewScrollPositionNone];
Run Code Online (Sandbox Code Playgroud)

这适用于"人"案例但不适用于其他案例.我曾尝试设置allowMultipleSelectionYES并解决了选择的问题,但它是不能接受的应用程序逻辑的条款.

我错过了一些关于这些功能如何工作的内容吗 如何以编程方式在单个选择表中选择一行?

Bar*_*uch 9

修复了以下模板:

// Uncomment the following line to preserve selection between presentations.
self.clearsSelectionOnViewWillAppear = NO;
Run Code Online (Sandbox Code Playgroud)

仍然不确定为什么以前它不起作用.