Ios 如何在UIPicker中首先选择具有特定标题的数组
您好,我想在UIPicker中显示一个列表,它保存在数组中 它可以工作,但我想选择一个特定的标题作为标准。它应该是自动选择的 例如: 排列 索引标题 0水Ios 如何在UIPicker中首先选择具有特定标题的数组,ios,objective-c,xcode,multidimensional-array,uipickerview,Ios,Objective C,Xcode,Multidimensional Array,Uipickerview,您好,我想在UIPicker中显示一个列表,它保存在数组中 它可以工作,但我想选择一个特定的标题作为标准。它应该是自动选择的 例如: 排列 索引标题 0水 1\ustrong>\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\ufire快速浏览一下文档将为您提供答案。这样做:记住您必须在ViewController生命周期的viewDidLoad上或之后的某个位置执行此操作 [myPickerView selectRow:index
1\ustrong>\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\ufire快速浏览一下文档将为您提供答案。这样做:记住您必须在ViewController生命周期的
viewDidLoad
上或之后的某个位置执行此操作
[myPickerView selectRow:indexYouWantSelected inComponent:columnInCaseYouHaveMany animated:NO];
为了实现这一点,您需要使用
首先你需要找到火的指数
NSArray *array = @[@"Water",@"Fire",@"Storm"];
NSString *stringToBeSelected = @"Fire";
NSUInteger index = [array indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
NSString *currentString = (NSString *)obj;
return [currentString isEqualToString:stringToBeSelected];
}];
选择pickerView的行
[self.pickerView selectRow:index inComponent:0 animated:YES];
通过索引1,你的意思是选择器应该总是选择中间的行吗?不,它应该总是选择标题为Fire的行。我不知道数组的索引,只知道标题。我需要选择title=fire的那一行谢谢你的解决方案我明天会查出来告诉你works@ErayGeveci-好的..我在等你的重播:)一切都好:)
[self.pickerView selectRow:index inComponent:0 animated:YES];