gpt4 book ai didi

iphone - selectRowAtIndexPath 仅在 allowsMultipleSelection 为 YES 时有效

转载 作者:可可西里 更新时间:2023-11-01 06:22:19 24 4
gpt4 key购买 nike

我有一个 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];

这适用于“People”案例,但不适用于其他案例。我曾尝试将 allowMultipleSelection 设置为 YES 并解决了选择问题,但就应用程序逻辑而言,这是 Not Acceptable 。

我是否遗漏了有关这些功能如何工作的信息?如何以编程方式在单个选择表中选择一行?

最佳答案

修复了模板中的以下内容:

// Uncomment the following line to preserve selection between presentations.
self.clearsSelectionOnViewWillAppear = NO;

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

关于iphone - selectRowAtIndexPath 仅在 allowsMultipleSelection 为 YES 时有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12005315/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com