Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在UIPicker中首先选择具有特定标题的数组_Ios_Objective C_Xcode_Multidimensional Array_Uipickerview - Fatal编程技术网

Ios 如何在UIPicker中首先选择具有特定标题的数组

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

您好,我想在UIPicker中显示一个列表,它保存在数组中

它可以工作,但我想选择一个特定的标题作为标准。它应该是自动选择的

例如:

排列

索引标题

0水


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];