I have a UIView which i am presenting to the user which contains a UIPickerView to select between different values. When this view is shown, it is shown asynchronously and my method which opened the UIView has ending before getting any meaningful data from the UIPickerView.
Is there a way to present such controls modally while halting execution of the opening 开发者_JAVA百科method so that i can test the results after they have been selected?
I've tried presenting the UIPickerView inside a UIView and UIAlertView and both are the same, my method returns before i've used the controls.
i've tried:
[self presentModalViewController:self.Picker animated:YES];
and still no joy.
You definitely don't want -presentModalViewController:Animated:. That method is intended to present UIViewControllers, and your Picker is a regular ol' UIView. As for your specific question, the quick answer is "No".
What you're going for here requires a slightly different design philosophy. Instead of having one method to both present the picker and get input from it as you desire, you'll need 2 methods: one to present the picker, probably with UIView's animation methods, and another to act on input from it.
Specifically, by setting yourself as the delegate of the UIImagePicker, you can present it and be assured that later, at some undefined time in the future, the picker will tell you (via pickerView:didSelectRow:inComponent: delegate method) that it has selected an item. At this time, you can test the selected values and act accordingly. Take a look at the UIPickerViewDelegate Protocol Reference for details on the delegate methods.
No.
Stopping execution in the UI thread will just block and lock up the UI. This is not the proper way to do event driven code.
Instead of halting/blocking and waiting for the results, you need to break your code up into 2 methods. The first to bring up the picker and then return immediately, and the second to do whatever you originally wanted to do in your method after halting/pausing your code. Have the picker call this second method when it has the results you need.
精彩评论