Currently, I am facing big problems with my ActionSheet. It works great on the iPhone, but on the iPad it just crashes
I create a new project with only one button
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", style: UIAlertActionStyle.Default, 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. } }
As I said on the iphone, it works, but if I press the button on the iPad, the application will work with
2014-09-25 14: 54: 52.784 test [9541: 1970048] * Application termination due to uncovered exception "NSGenericException", reason: "Your application has submitted UIAlertController () style UIAlertControllerStyleActionSheet. Modular specification is UIAlertController with this UIModalPresentationPoperopover style. must provide the location information for this popover through the alert controller popoverPresentationController. You must provide sourceView and sourceRect or barButtonItem. If this information is not known when you present the alert controller, you can provide it in the UIPopoverPresentationControllerDelegate -prepareForPopoverPreover method sentation. * First stack of throw calls: (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 _applyBlockToCFArrayCopToIK 8StIK
0x00e4d3ee _afterCACommitHandler + 545 9 CoreFoundation
0x00536fbe __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30 10 CoreFoundation 0x00536f00 __CFRunLoopDoObservers + 400 11 CoreFoundation 0x0052c93a __CFRunLooprunFoRunFoRunFoRunFoRunFoRunFoRunFoRunFoRunFoRunFoRunFoRunFoRunFoRunFoFun1Funfunfunfunfunfunfunpfun1funfunfunfunfunfunpfun1fun2fun1fun1fun1fun2fcfcfcfcfcfcfcfcdcfc
0x0052bfdb CFRunLoopRunInMode + 123 14 GraphicsServices
0x0438424f GSEventRunModal + 192 15 Graphics Services
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) lib ++ abi.dylib: termination with a non-displayable exception of type NSException
The project can be found at https://www.dropbox.com/s/54jqd8nsc67ll5g/test.zip?dl=0 to download and try.
iphone swift ipad uiactionsheet
Fabian Boulegue Sep 25 '14 at 12:56 on 2014-09-25 12:56
source share