iphone – Swift UIAlertController – > ActionSheet iPad iOS8崩溃

iphone – Swift UIAlertController – > ActionSheet iPad iOS8崩溃,第1张

概述目前我遇到了大麻烦与我的ActionSheet。在iPhone它工作伟大,但在iPad它只是崩溃 我创建一个只有一个按钮的新项目 import UIKitextension ViewController : UIActionSheetDelegate { func actionSheet(actionSheet: UIActionSheet, didDismissWithButton 目前我遇到了大麻烦与我的ActionSheet。在iPhone它工作伟大,但在iPad它只是崩溃

我创建一个只有一个按钮的新项目

import UIKitextension 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上的按钮应用程序崩溃

2014-09-25 14:54:52.784 test[9541:1970048] * 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.’
* First throw call stack: ( 0 CoreFoundation 0x00613df6 exceptionPreprocess + 182 1 libobjc.A.dylib
0x01fdaa97 objc_exception_throw + 44 2 UIKit
0x0164da37 -[UIPopoverPresentationController
presentationTransitionWillBegin] + 3086 3 UIKit
0x00f54f75 __71-[UIPresentationController
_initVIEwHIErarchyForPresentationSupervIEw:]_block_invoke + 1666 4 UIKit 0x00f53554
__56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 226 5 UIKit
0x00f8721b __40+[UIVIEwController _scheduleTransition:]_block_invoke +
18 6 UIKit 0x00e4d62e
___afterCACommitHandler_block_invoke + 15 7 UIKit 0x00e4d5d9 _applyBlockToCFArraycopIEdToStack + 415 8 UIKit
0x00e4d3ee _afterCACommitHandler + 545 9 CoreFoundation
0x00536fbe
__CFRUNLOOP_IS_CALliNG_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30 10 CoreFoundation 0x00536f00 __CFRunLoopDoObservers
+ 400 11 CoreFoundation 0x0052c93a __CFRunLoopRun + 1226 12 CoreFoundation 0x0052c1ab CFRunLoopRunspecific + 443 13 CoreFoundation
0x0052bfdb CFRunLoopRunInMode + 123 14 GraphiCSServices
0x0438424f GSEventRunModal + 192 15 GraphiCSServices
0x0438408c GSEventRun + 104 16 UIKit
0x00e23e16 UIApplicationMain + 1526 17 test
0x00085e9e top_level_code + 78 18 test
0x00085edb main + 43 19 libdyld.dylib
0x0273eac9 start + 1 20 ???
0x00000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught
exception of type NSException

项目可以在https://www.dropbox.com/s/54jqd8nsc67ll5g/test.zip?dl=0找到下载并尝试。

解决方法 错误消息告诉您,您需要给警报控制器的popoverPresentationController一个位置,以便它可以正确定位本身。这很容易做 – 只需检查是否有一个popover控制器,并添加发件人作为源。

如果你的按钮是一个UIbarbuttonItem:

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崩溃所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1087688.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存