更好的方法是使用操作表而不是帶有兩個按鈕的彈出窗口。
建立從標籤欄項目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 然後,請問具體問題 –