ios - 如何使用默认值在 alertView 中创建 tableView?

标签 ios swift uitableview uialertcontroller

我的代码是这样的:

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/

相关文章:

ios - 如何在 Swift 中对子类化的 UIViewController 进行类型转换?

swift - 是否可以以编程方式禁用 commitEditingStyle?

swift - 使用 SDWebimage 下载并缓存 MKMapSnapshotter 图像

ios - 在 UITableViewHeaderFooterView 中有一个按钮

html - iOS safari 支持播放跨域音频吗?

ios - iOS Wifi直接通讯

ios - 将重新排序图标设置为透明 UITableViewCells - moverowat 函数

ios - 双segue tableView?

iphone - 复制内容并删除 webview 时 UIWebview 崩溃

ios - Swift SpriteKit-将所有场景音频静音