Search code examples
iphonexcodeuipickerviewuisegmentedcontroluiactionsheet

UIActionSheet with UIPickerView and Done, Next, Previous buttons


i am trying to implement an action sheet that contains a picker view and a segmented control bar with a previous button, next button and done button like the image as follows https://i.sstatic.net/SX61b.jpg. I currently am able to make it look like this https://i.sstatic.net/jpljb.jpg. I was wondering if someone could help me get the picker view to sit on the bottom and just make it look a little better. Thanks for any help.


Solution

  • Unless you're targeting very old versions of iOS (i.e. versions earlier than 3.2), the best way to do it is to take a completely different approach.

    As of 3.2, any UIResponder (which includes all UIViews) can return a UIView from its inputView property to show that view instead of the keyboard when the view becomes the first responder. This even works for views that normally don't become first responder or don't display the keyboard at all. It's simple:

    1. Design your popup view, as you would any other view.
    2. Ensure that your widget view returns YES from canBecomeFirstResponder.
    3. Ensure that your widget view returns an instance of your popup view from inputView.

    More details are available in the documentation.

    Also, BTW, if you're on an iPad you should probably use a UIPopoverController to display a UIPickerView instead of either of these methods. Apple may actually require this if you intend to get your app in the app store.