大佬教程收集整理的这篇文章主要介绍了iphone – Swift UIAlertController – > ActionSheet iPad iOS8崩溃,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
import UIKit 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" } } } } class ViewController: UIViewController,UIActionSheetDelegate { @IBACtion func test(sender: AnyObject) { 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",handler: { (action: UIAlertAction!) -> () in // doing something for "video" }) alertController.addAction(cancelAction) alertController.addAction(button1action) alertController.addAction(button2action) self.presentViewController(alertController,animated: true,completion: nil) } } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
因为我伤心在iphone它的工作,但如果我点击iPad上的按钮应用程序崩溃
项目可以在https://www.dropbox.com/s/54jqd8nsc67ll5g/test.zip?dl=0找到下载并尝试。
if let popoverController = alertController.popoverPresentationController { popoverController.barButtonItem = sender } self.presentViewController(alertController,completion: nil)
除此以外:
if let popoverController = alertController.popoverPresentationController { popoverController.sourceView = sender popoverController.sourceRect = sender.bounds } self.presentViewController(alertController,completion: nil)
以上是大佬教程为你收集整理的iphone – Swift UIAlertController – > ActionSheet iPad iOS8崩溃全部内容,希望文章能够帮你解决iphone – Swift UIAlertController – > ActionSheet iPad iOS8崩溃所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。