问题
This issue is driving me crazy. I have a UIPickerView that I loaded in viewDidLoad, and I need to initialize the selected row that is to appear on the screen. My code is as follows:
self.pickerSkins.delegate = self;
[self.pickerSkins reloadAllComponents];
NSLog(@"%d", [self.pickerSkins numberOfRowsInComponent:0]);
[self.pickerSkins selectRow:1 inComponent:0 animated:NO];
I have put this in viewDidLoad. NSLog logs a value of 2. However, the selected row that pops up is always the first row and not the second.
If I put the selectRow in viewWillAppear, it also doesn't work.
If I put the selectRow in viewDidAppear, the PickerView appears and then goes to the second row.
UPDATE: If I have more than 2 rows, the method works correctly from viewDidLoad, unless I am scrolling to the last row. The method never works in viewDidLoad or viewWillAppear if I am scrolling to the last row. Any idea why this is? Thanks.
How do I get the selected row to be the second row before the view appears?
Thanks.
来源:https://stackoverflow.com/questions/16114054/uipickerview-selectrowincomponentanimated-not-working-in-viewdidload-but-worki