Reputation:
I need a way of allowing a user to pick on option out of a list, I'm thinking of using a UIPickerView
in a UIAlertView
. However I was wondering if:
UIPickerView
in a UIAlertView
easily in iOS 5
(if so is it frowned upon by apple & will be app be rejected?)Any help or advice would be really appreciated!
Upvotes: 2
Views: 5202
Reputation: 2682
1) You can easily do this in any of the iOS SDK versions, I believe. Since UIAlertViews
are basically subclassed UIViews
, you can simply use addSubview:
2) This depends the context of the options list. For choices like birthdays or date or time, Apple uses a separate UIViewController
with a UITableView
(one row) and a UIPickerView
. If it's none of the three above, Apple generally seems to use a UITableView
which puts a checkmark next to the person's choice.
Either way, I think everyone seems to agree that you should bring up a second page with the list of options.
Upvotes: 0
Reputation: 119242
If you are choosing a value to be put into a text field on the screen, just make your picker view the inputView
of the text field. It will then animate into place for you just like the keyboard.
You may also wish to add a toolbar as an inputAccessoryView
with done, next etc. buttons on it.
Making the picker view the input view is very simple. In your viewDidLoad method, create the picket view, setting its datasource and delegate as normal, then just assign it to the input view property of the text field:
myTextField.inputView = myPicker;
In your picker view delegate methods, you can update the text field with the selected value when the picker's selection is changed. In your text field delegate methods, you can make sure the picket has the right value selected before it appears (willBeginEditing? (guess, not at the mac ATM)).
The accessory view can just be a UIToolbar with a single done item that tells the text field to resign first responder status. Again, set this up and assign it in viewDidLoad.
Upvotes: 6
Reputation: 1865
If you have 2-3 choices put several buttons into UIAlertView after otherButtonTitles:. If you have more choices, definitely you need to build new view controller. Don't even try to add picker view into UIAlertView.
Upvotes: 2
Reputation: 7148
It's certainly possible to add a UIPickerView
as a subview of a UIAlertView
, and I doubt Apple would reject your app because of it, but I think it would make for a poor UI. Why not just create a new UIViewController
subclass to contain the UIPickerView
and present it modally? That's a much more common interaction pattern.
Upvotes: 2