如何在swift iOS中的UIAlertcontroller中显示UITableview?
我对swift编码非常陌生,因此我想知道是否有任何方法可以使用swift在alertcontroller中显示tableview。您的要求是什么?请参阅此部分,谢谢,我可以显示tableview,但如何在tableview单元格单击时关闭相同的uialertcontroller?如果您能稍微解释一下代码的作用,那么实际上它可以节省一些时间。谢谢。:)如何在swift iOS中的UIAlertcontroller中显示UITableview?,ios,swift,uitableview,uialertcontroller,Ios,Swift,Uitableview,Uialertcontroller,我对swift编码非常陌生,因此我想知道是否有任何方法可以使用swift在alertcontroller中显示tableview。您的要求是什么?请参阅此部分,谢谢,我可以显示tableview,但如何在tableview单元格单击时关闭相同的uialertcontroller?如果您能稍微解释一下代码的作用,那么实际上它可以节省一些时间。谢谢。:) var alrController = UIAlertController(title: "\n\n\n\n\n\n", message: nil
var alrController = UIAlertController(title: "\n\n\n\n\n\n", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
let margin:CGFloat = 8.0
let rect = CGRectMake(margin, margin, alrController.view.bounds.size.width - margin * 4.0, 100.0)
var tableView = UITableView(frame: rect)
tableView.delegate = self
tableView.dataSource = self
tableView.backgroundColor = UIColor.greenColor()
alrController.view.addSubview(tableView)
let somethingAction = UIAlertAction(title: "Something", style: UIAlertActionStyle.Default, handler: {(alert: UIAlertAction!) in println("something")})
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: {(alert: UIAlertAction!) in println("cancel")})
alrController.addAction(somethingAction)
alrController.addAction(cancelAction)
self.presentViewController(alrController, animated: true, completion:{})
private var alertController = UIAlertController()
private var tblView = UITableView()
private func setupCitySelectionAlert() {
let alertVC = UIViewController.init()
let rect = CGRect(x: 0.0, y: 0.0, width: 300.0, height: 300.0)
alertVC.preferredContentSize = rect.size
tblView = UITableView(frame: rect)
tblView.delegate = self;
tblView.dataSource = self;
tblView.tableFooterView = UIView(frame: .zero)
tblView.separatorStyle = .singleLine
alertVC.view.addSubview(tblView)
alertVC.view.bringSubviewToFront(tblView)
alertVC.view.isUserInteractionEnabled = true
tblView.isUserInteractionEnabled = true
tblView.allowsSelection = true
self.alertController = UIAlertController(title: "Title", message: nil, preferredStyle: .alert)
alertController.setValue(alertVC, forKey: "contentViewController")
let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: nil)
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: nil)
}