我有一個兼容iPhone和iPad佈局的應用程序。對於iPhone佈局,我爲iPad創建了Action Sheet和Pop。問題是彈出的箭頭不指向我點擊的按鈕。下面是我的代碼....彈出窗口不會指向按鈕
let actionSheet = UIAlertController(title: "Choose an option",
message: "Message",
preferredStyle: .ActionSheet)
...
if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad
{
// for iPad
actionSheet.popoverPresentationController?.sourceView = self.view
actionSheet.popoverPresentationController?.sourceRect = self.view.bounds;
actionSheet.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.allZeros;
}
self.presentViewController(actionSheet, animated: true, completion: nil)
好吧,沒有工作無論是。該按鈕實際上是一個'UIBarButtonItem'。我改變了函數作爲'@IBAction func userOptions(button:UIBarButtonItem)',並且它拋出一個錯誤:'[UIBarButtonItem bounds]:無法識別的選擇器發送' –
檢查我的修改答案@SrujanSimha – rakeshbs
完美!謝謝你:) –