我使用下面的代碼爲警報視圖,它在iPhone中工作。但是當我在iPad上運行它,它給了以下錯誤:警報視圖的UIAlertController中的UIPickerView僅在iPhone中正確時在iPad中給出錯誤?
Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController() of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'
代碼如下:
let alertView = UIAlertController(title: "Select Launguage", message: "\n\n\n\n\n\n\n\n\n\n", preferredStyle: UIAlertControllerStyle.ActionSheet);
pickerView.center.x = self.view.center.x
alertView.view.addSubview(pickerView)
let action = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)
alertView.addAction(action)
presentViewController(alertView, animated: true, completion: nil)
請幫助我。爲什麼它不適用於iPad ...
這裏看你需要做什麼:http://stackoverflow.com/questions/24224916/presenting-a-uialertcontroller-properly-on-an-ipad-using-ios-8 – totiG
我嘗試一個之前。但只在iPad上工作。不在iPhone上工作。 –