I want to show UIPickerView in UIAlertController or UIPopoverController, I am new to iOS, please give me some example code here.
I searched for them but can't find any satisfactory answers. I don't want to do it on UIActionSheet, because it is deprecated in iOS 9. Also I want it in Swift not in Obj-C. I tried the below example but it is not working for me.
http://makeapppie.com/2014/08/30/the-swift-swift-tutorials-adding-modal-views-and-popovers/
Your Basic Code Look Like:
let alert = UIAlertController(title: title, message: message, preferredStyle: .actionSheet)
alert.isModalInPopover = true
// Create a frame (placeholder/wrapper) for the picker and then create the picker
let pickerFrame = CGRect(x: 17, y: 52, width: 270, height: 100) // CGRectMake(left), top, width, height) - left and top are like margins
let picker = UIPickerView(frame: pickerFrame)
// set the pickers datasource and delegate
picker.delegate = self
picker.dataSource = self
// Add the picker to the alert controller
alert.view.addSubview(picker)
//Do stuff and action on appropriate object.
Please review below answer.
Is there any way to add UIPickerView into UIAlertController (Alert or ActionSheet) in Swift?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With