2016-08-10 76 views
3

我對swift編碼非常陌生,所以我想知道是否有任何方法可以在alertcontroller中使用swift顯示tableview。如何在swift iOS中的UIAlertcontroller中顯示UITableview?

+0

最新要求? –

+0

看到這一次http://stackoverflow.com/questions/20737426/how-to-insert-the-uitextview-into-uialertview-in-ios –

+0

謝謝,我能夠顯示tableview,但如何解僱相同的uialertcontroller tableview單元格點擊? – Harry

回答

4
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:{}) 
相關問題