我的代码是这样的:
let alrController = UIAlertController(title: "Membri", message: nil, preferredStyle: UIAlertControllerStyle.actionSheet)
tableView.backgroundColor = UIColor.white
alrController.view.addSubview(tableView)
let cancelAction = UIAlertAction(title: "Esci", style: UIAlertActionStyle.cancel, handler: {(alert: UIAlertAction!) in})
alrController.addAction(cancelAction)
self.present(alrController, animated: true, completion:{})
我想在我的数组中使用以下值填充(但我不知道如何)tableView
:names["name1","name2","name3"]
有人可以帮助我吗?
最佳答案
要填充操作表,您无需添加 tableView。相反,您只需添加操作,它就会私下创建和管理 tableView。
有关最近的教程,请参阅 UIAlertController Examples
我们的想法是,您将为数组中的每个字符串创建一个 UIAlertAction,包括一个闭包,用于说明当用户点击该操作行时要执行的操作。
for name in names
{
let namedAction = UIAlertAction(title: name, style: .default)
{ (action) in
// do something when this action is chosen (tapped)
}
alrController.addAction(namedAction)
}
关于ios - 如何使用默认值在 alertView 中创建 tableView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45652763/