这是我用于在actionSheet样式中显示和处理UIAlertController
的代码。
actionSheetController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
actionSheetController.view.tintColor = TGProjectHandler.getAppThemeColor()
let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in
//Just dismiss the action sheet
}
actionSheetController.addAction(cancelAction)
let inviteMemberAction: UIAlertAction = UIAlertAction(title: "Invite member", style: .default) { action -> Void in
let newActivityInviteTableController = NewActivityInviteTableViewController()
newActivityInviteTableController.invite_type = 1
newActivityInviteTableController.activity = self.activity
self.invitation_type = 1
let navController = UINavigationController(rootViewController: newActivityInviteTableController)
navController.navigationBar.barTintColor = self.navigationController?.navigationBar.barTintColor
navController.navigationBar.tintColor = self.navigationController?.navigationBar.tintColor
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
navController.navigationBar.isTranslucent = false
newActivityInviteTableController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(self.dismissPopover))
newActivityInviteTableController.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Add", style: .plain, target: newActivityInviteTableController.self, action: #selector(newActivityInviteTableController.sendInviteRequest))
if (!(newActivityInviteTableController == nil))
{
self.navigationController!.present(navController, animated: true, completion: nil)
}
}
actionSheetController.addAction(inviteMemberAction)
let inviteChildAction: UIAlertAction = UIAlertAction(title: "Invite child", style: .default)
{ action -> Void in
let newActivityInviteChildTableController = NewActivityInviteChildTableViewController()
self.invitation_type = 2
newActivityInviteChildTableController.activity = self.activity
let navController = UINavigationController(rootViewController: newActivityInviteChildTableController)
navController.navigationBar.barTintColor = self.navigationController?.navigationBar.barTintColor
navController.navigationBar.isTranslucent = false
navController.navigationBar.tintColor = UIColor.white
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
newActivityInviteChildTableController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(self.dismissPopover))
newActivityInviteChildTableController.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Add", style: .plain, target: newActivityInviteChildTableController.self, action: #selector(newActivityInviteChildTableController.sendInviteRequest))
if (!(newActivityInviteChildTableController == nil))
{
self.navigationController!.present(navController, animated: true, completion: nil)
}
}
actionSheetController.addAction(inviteChildAction)
self.present(actionSheetController, animated: true, completion: nil)
虽然是随机的,但有时它会让应用程序无响应。如果我多次显示/关闭 actionSheetController ,则 actionSheetController 会保留在屏幕上,然后应用就会无响应触摸。