更好的方法是使用操作表而不是带有两个按钮的弹出窗口。
建立从标签栏项目3出口到你的ViewController,请确保您设置的连接为一个行动,给函数的名称,在这个例子中我将其称之为“presentCameraAndPhotos”
@IBAction func presentCameraAndPhotos(_ sender: Any) {
var alert = UIAlertController(title: "Foo", message: "Bar", preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: .default) { _ in
//Do whatever it is you want to do when camera is selected
self.performSegue(withIdentifier: "CameraVCSegueID", sender: self)
})
alert.addAction(UIAlertAction(title: "Photos", style: .default) { _ in
//Do whatever it is you want to do when photos is selected
self.performSegue(withIdentifier: "PhotoVCSegueID", sender: self)
})
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
present(alert, animated: true, completion: nil)
}
唐忘了准备赛段。
如果这是为iPad,在VC标签栏3项设置的出口,并且使用类似这个:
@IBAction func presentCameraAndPhotos(_ sender: Any) {
var alert = UIAlertController(title: "Foo", message: "Bar", preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: .default) { _ in
//Do whatever it is you want to do when camera is selected
self.performSegue(withIdentifier: "CameraVCSegueID", sender: self)
})
alert.addAction(UIAlertAction(title: "Photos", style: .default) { _ in
//Do whatever it is you want to do when photos is selected
self.performSegue(withIdentifier: "PhotoVCSegueID", sender: self)
})
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alert.modalPresentationStyle = .Popover
let popoverPresentation = alert.popoverPresentationController
popoverPresentation.barButtonItem = //Whatever the outlet name of your tab bar 3 is
present(alert, animated: true, completion: nil)
}
做出第一现有解决方案进行调查。 我推荐这个网站https://www.cocoacontrols.com/search?q=tabbar 然后,请问具体问题 –