UIActionSheet在iPad swift上崩溃



我在工具栏中有以下按钮操作:

  @IBAction func share(sender: AnyObject) {
        let modifiedURL1 = "http://www.declassifiedandratified.com/search.html?q=(self.searchBar.text)"
        let modifiedURL = modifiedURL1.stringByReplacingOccurrencesOfString(" ", withString: "%20", options: NSStringCompareOptions.LiteralSearch, range: nil)
        let alert = UIAlertController(title: "Share", message: "Share your findings", preferredStyle: UIAlertControllerStyle.ActionSheet)
        let twBtn = UIAlertAction(title: "Twitter", style: UIAlertActionStyle.Default) { (alert) -> Void in
            if SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter){
                var twitterSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
                twitterSheet.setInitialText("Look what I found on Declassified and Ratified: (modifiedURL)")
                self.presentViewController(twitterSheet, animated: true, completion: nil)
            } else {
                var alert = UIAlertController(title: "Accounts", message: "Please login to a Twitter account to share.", preferredStyle: UIAlertControllerStyle.Alert)
                alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
                self.presentViewController(alert, animated: true, completion: nil)
            }
        }
        let fbBtn = UIAlertAction(title: "Facebook", style: UIAlertActionStyle.Default) { (alert) -> Void in
            if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook){
                var facebookSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
                facebookSheet.setInitialText("Look what I found on Declassified and Ratified: (modifiedURL)")
                self.presentViewController(facebookSheet, animated: true, completion: nil)
            } else {
                var alert = UIAlertController(title: "Accounts", message: "Please login to a Facebook account to share.", preferredStyle: UIAlertControllerStyle.Alert)
                alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
                self.presentViewController(alert, animated: true, completion: nil)
            }
        }
        let safariBtn = UIAlertAction(title: "Open in Safari", style: UIAlertActionStyle.Default) { (alert) -> Void in
            let URL = NSURL(string: modifiedURL)
            UIApplication.sharedApplication().openURL(URL!)
        }
        let cancelButton = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (alert) -> Void in
            println("Cancel Pressed")
        }
        let textBtn = UIAlertAction(title: "Message", style: UIAlertActionStyle.Default) { (alert) -> Void in
            if (MFMessageComposeViewController.canSendText()) {
                let controller = MFMessageComposeViewController()
                controller.body = "Look what I found on Declassified and Ratified: (modifiedURL)"
                controller.messageComposeDelegate = self
                self.presentViewController(controller, animated: true, completion: nil)
            }
        }

        alert.addAction(twBtn)
        alert.addAction(fbBtn)
        alert.addAction(safariBtn)
        alert.addAction(textBtn)
        alert.addAction(cancelButton)
        self.presentViewController(alert, animated: true, completion: nil)
    }

然而,当在iPad上调用此代码时,会发生sigbart崩溃(这是我在控制台中看到的全部内容)。我知道这是一个常见的问题,但其他解决方案对我不起作用。我甚至将版本设置为最新的iOS,但这并没有解决问题。有人能解释吗?

在iPad上,操作表是一个弹出窗口。因此,必须为其UIPopoverPresentationContainer提供一个sourceViewsourceRectbarButtonItem,以便它可以将箭头附加到其上。

最新更新