Swift UIActionSheet crashes on iPad?

I am currently in complete frustration as I cannot find any errors, but my ActionSheet crashes on the iPad but works well on the iPhone, here is the action code

if (view.annotation.title as String!) == "San Francisco" { currentLat = 37.615223 currentLong = -122.389977 url = "www.google.de" let action:UIActionSheet = UIActionSheet(title: "Change Map Type", delegate: self, cancelButtonTitle: "Back", destructiveButtonTitle: nil, otherButtonTitles: "Product Page", "Video") action.showInView(self.view) action.tag = 0 VideoID = "XXXXXX" } 

So the action that needs to be processed is

 if actionSheet.tag == 0{ if buttonIndex == 1{ performSegueWithIdentifier("showShop", sender: self) } if buttonIndex == 2{ UIApplication.sharedApplication().openURL(NSURL(string: "http://www.youtube.com/watch?v=\(youtubeVideoID)")) } //if buttonIndex == 2{ performSegueWithIdentifier("showYoutube", sender: self) } } 

Youtube works fine on iPhone and iPad, showShop works fine on iPhone, but not on iPad

"showShop" go to my ViewControllerShopView, which looks like

 import UIKit class ViewControllerShopView: UIViewController { /* ################################################## IBOutlets ################################################## */ @IBOutlet weak var activity3: UIActivityIndicatorView! @IBOutlet weak var webView: UIWebView! /* ################################################## viewDidLoad ################################################## */ override func viewDidLoad() { super.viewDidLoad() loadurl() } /* ################################################## didReceiveMemoryWarning ################################################## */ override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() println("memory warning") } /* ################################################## viewWillAppear ################################################## */ override func viewWillAppear(animated: Bool) { loadurl() } /* ################################################## loadurl func ################################################## */ func loadurl(){ var loadingurl = "google.com" var homeurl = "google1.com" loadingurl = url let webviewURL = NSURL(string: loadingurl) let request = NSURLRequest(URL: webviewURL) webView.loadRequest(request) } /* ################################################## HomeButton ################################################## */ @IBAction func Reload(sender: AnyObject) { var loadingurl = "google.com" var homeurl = "google1.com" loadingurl = url let webviewURL = NSURL(string: loadingurl) let request = NSURLRequest(URL: webviewURL) webView.loadRequest(request) } /* ################################################## Activity Indicator ################################################## */ func webViewDidStartLoad(_ : UIWebView){activity3.startAnimating()} func webViewDidFinishLoad(_ : UIWebView){activity3.stopAnimating()} } 

but Segue was never made on an iPad, it just crashes on Segue.

Can anyone understand what might be wrong?

+1
swift ipad uiactionsheet
Sep 25 '14 at 11:37
source share
2 answers

You need to check the version of the system at run time if your project supports both iOS7 and iOS8; you can paste this snippet into any of your methods:

 let systemVersion: NSInteger = (UIDevice.currentDevice().systemVersion as NSString).integerValue if systemVersion < 8 { // iOS7: let action:UIActionSheet = UIActionSheet(title: "Change Map Type", delegate: self, cancelButtonTitle: "Back", destructiveButtonTitle: nil, otherButtonTitles: "Product Page", "Video") action.tag = 0 action.showInView(self.view) } else { // iOS8: let alertController: UIAlertController = UIAlertController(title: "Change Map Type", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet) let cancelAction: UIAlertAction = UIAlertAction(title: "Back", style: UIAlertActionStyle.Cancel, handler: nil) let button1action: UIAlertAction = UIAlertAction(title: "Product Page", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) -> () in // doing something for "product page" }) let button2action: UIAlertAction = UIAlertAction(title: "Video", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) -> () in // doing something for "video" }) alertController.addAction(cancelAction) alertController.addAction(button1action) alertController.addAction(button2action) // for iPAD support: alertController.popoverPresentationController?.sourceView = self.view alertController.popoverPresentationController?.sourceRect = CGRectMake(self.view.bounds.width / 2.0, self.view.bounds.height / 2.0, 1.0, 1.0) // this is the center of the screen currently but it can be any point in the view self.presentViewController(alertController, animated: true, completion: nil) } 

and your class should match UIActionSheetDelegate for the UIActionSheet class:

 extension ViewController : UIActionSheetDelegate { func actionSheet(actionSheet: UIActionSheet, didDismissWithButtonIndex buttonIndex: Int) { if actionSheet.tag == 0 { if buttonIndex == 1 { // doing something for "product page" } else if (buttonIndex == 2) { // doing something for "video" } } } } 
+5
Sep 25 '14 at 12:30
source share

also tried this

 @IBAction func BTfindme(sender: AnyObject) { let actionSheetController: UIAlertController = UIAlertController(title: "Action Sheet", message: "Test", preferredStyle: .ActionSheet) let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in } actionSheetController.addAction(cancelAction) let ActionOne: UIAlertAction = UIAlertAction(title: "Action one", style: .Default) { action -> Void in } actionSheetController.addAction(ActionOne) let ActionTwo: UIAlertAction = UIAlertAction(title: "Action two", style: .Default) { action -> Void in } ActionTwo.addAction(choosePictureAction) self.presentViewController(actionSheetController, animated: true, completion: nil) } 

and it also crashes on the ipad but not on the iphone

-one
Sep 25 '14 at 12:18
source share



All Articles