ios – 想在UIAlertController或UIPopoverController Swift中显示UIPickerView吗?

我想在UIAlertController或UIPopoverController中显示UIPickerView,我是iOS新手,请在这里给我一些示例代码.

搜索了他们但找不到任何满意的答案.我不想在UIActionSheet上这样做,因为它在iOS 9中已被弃用.我也希望它在Swift中而不是在Obj-C中.我尝试了下面的例子,但它不适合我.

http://makeapppie.com/2014/08/30/the-swift-swift-tutorials-adding-modal-views-and-popovers/

解决方法

你的基本代码看起来像:
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.

请查看以下答案.

Is there any way to add UIPickerView into UIAlertController (Alert or ActionSheet) in Swift?

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...