动态填充操作 sheet
Fill action sheet dynamically
我正在寻找一种方法来使用对象列表中的数据创建一个浮动列表(AlertView 中的 TableView),然后单击一个元素即可获得对所选对象的引用。
为此,我使用了一个动作 sheet 和一个 for 循环,如下所示
@IBAction func btnShowList_onClick(_ sender: Any) {
let alertController = UIAlertController(title: "Action Sheet", message: "List of Superheroes", preferredStyle: .actionSheet)
for item in arrSuperHeroes{
let superbutton = UIAlertAction(title: (item as! SuperHeroe).nombre , style: .default, handler: { (action) in
self.superSel = item as! SuperHeroe
print(self.superSel.name)
})
alertController.addAction(superbutton)
}
self.navigationController!.present(alertController, animated: true, completion: nil)
}
但是我在执行最后一行的时候出现了这个错误
fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
有人可以帮助我吗?怎么了?还有其他方法吗?
我认为您需要按如下方式显示警报:
self.present(alertController, animated: true, completion: nil)
我正在寻找一种方法来使用对象列表中的数据创建一个浮动列表(AlertView 中的 TableView),然后单击一个元素即可获得对所选对象的引用。
为此,我使用了一个动作 sheet 和一个 for 循环,如下所示
@IBAction func btnShowList_onClick(_ sender: Any) {
let alertController = UIAlertController(title: "Action Sheet", message: "List of Superheroes", preferredStyle: .actionSheet)
for item in arrSuperHeroes{
let superbutton = UIAlertAction(title: (item as! SuperHeroe).nombre , style: .default, handler: { (action) in
self.superSel = item as! SuperHeroe
print(self.superSel.name)
})
alertController.addAction(superbutton)
}
self.navigationController!.present(alertController, animated: true, completion: nil)
}
但是我在执行最后一行的时候出现了这个错误
fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
有人可以帮助我吗?怎么了?还有其他方法吗?
我认为您需要按如下方式显示警报:
self.present(alertController, animated: true, completion: nil)