gpt4 book ai didi

ios - KNMultiItemSelector 预选项目不工作

转载 作者:行者123 更新时间:2023-11-29 03:20:48 25 4
gpt4 key购买 nike

我正在尝试在我的代码中实现 KNMultiItemSelector 以选择数组中的多个项目。我一直在尝试让选择器在初始化时显示一些已勾选的项目,但它似乎不起作用。我的代码如下:

for (Option* option in optionssList) {
NSString* name = [NSString stringWithFormat:@"%@", option.name];
KNSelectorItem* item = [[KNSelectorItem alloc] initWithDisplayValue:name selectValue:option.id imageUrl:nil];
[items addObject:item];
if ([_selectedOptions containsObject:item]) {
NSLog(@"Already selected");
[_selectedOptions addObject:item];
}
}

KNMultiItemSelector * selector = [[KNMultiItemSelector alloc] initWithItems:items
preselectedItems:_selectedOptions
title:@"List"
placeholderText:@"Select Options"
delegate:self];

selector.useRecentItems = YES;
selector.maxNumberOfRecentItems = 5;

UINavigationController * uinav = [[UINavigationController alloc] initWithRootViewController:selector];
uinav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; // iPhone
uinav.modalPresentationStyle = UIModalPresentationFormSheet; // iPad only
[self presentViewController:uinav animated:YES completion:nil];

如有任何帮助,我们将不胜感激。谢谢!

最佳答案

您遇到了 KNMultiItemSelector 中的错误:KNMultiItemSelector 初始化程序忽略了 preselectedItems。要解决此错误,请将要选择的项目的 selected 设置为 YES,并确保 preselectedItems 不为零。 (它不需要包含预选项。)例如:

KNSelectorItem *item = [[KNSelectorItem alloc] initWithDisplayValue:@"Item"];
item.selected = YES;

KNMultiItemSelector *selector = [[KNMultiItemSelector alloc] initWithItems:@[item]
preselectedItems:@[]
title:@"List"
placeholderText:@"Select Options"
delegate:self];

关于ios - KNMultiItemSelector 预选项目不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21125088/

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