然后我试图在点击单元格时调用操作表,这就是我所做的
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let alertController = UIAlertController(title: "Action Sheet", message: "What do you like to do", preferredStyle: .alert)
let okButton = UIAlertAction(title: "Done", style: .default, handler: { (action) -> Void in
print("Ok button tapped")
})
let deleteButton = UIAlertAction(title: "Skip", style: .destructive, handler: { (action) -> Void in
print("Delete button tapped")
})
alertController.addAction(okButton)
}
当我点击手机时,警报控制器没有显示。我错过了什么?
答案 0 :(得分:5)
你几乎就在那里,请确保同时添加deleteButton
- 动作并使用alertController
present(alertController, animated: true, completion: nil)
答案 1 :(得分:3)
您的工作表未显示,因为您没有展示。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell]
[HKEY_CLASSES_ROOT\*\shell\CleanDesktop - Add to persistent files]
[HKEY_CLASSES_ROOT\*\shell\CleanDesktop - Add to persistent files\command]
@="\"C:\\Users\\Admin\\PycharmProjects\\clean_desktop\\wescript.py\" %1"
答案 2 :(得分:1)
我们创建一个函数didSelectContact
,并使用func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
处理表视图中的选定单元格。如果点击了每个单元格,则此操作表将打开。
func didSelectContact(){
let alert = UIAlertController(title: "Choose Once", message: "What you want do with contact", preferredStyle: UIAlertControllerStyle.actionSheet)
let call = UIAlertAction(title: "Call", style: UIAlertActionStyle.default) { (UIAlertAction) in
}
let sms = UIAlertAction(title: "SMS", style: UIAlertActionStyle.default) { (UIAlertAction) in
}
let cancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil)
alert.addAction(call)
alert.addAction(sms)
alert.addAction(cancel)
self.present(alert, animated: true, completion: nil)
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath:
IndexPath) {
self.didSelectContact()
}