Error displaying UIAlertView in fast

I am trying to show UIAlertView in my quick application

alert = UIAlertView(title: "", message: "bla", delegate: self, cancelButtonTitle: "OK") alert!.show() 

=> BAD_ACESS error in: - [_ UIAlertViewAlertControllerShim initWithTitle: message: delegate: cancelButtonTitle: otherButtonTitles:] ()

so I suspected myself. I set it to nil

  alert = UIAlertView(title: "", message: "bla", delegate: nil, cancelButtonTitle: "OK") alert!.show() 

=> ARM_DA_ALIGN error in: - [_ UIAlertViewAlertControllerShim initWithTitle: message: delegate: cancelButtonTitle: otherButtonTitles:] ()




full code

 import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, UIAlertViewDelegate { @lazy var window = UIWindow(frame: UIScreen.mainScreen().bounds) @lazy var locationManager = CLLocationManager() var alert: UIAlertView? = nil func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { //setup dummy window self.window.backgroundColor = UIColor.whiteColor() self.window.rootViewController = UIViewController() self.window.makeKeyAndVisible() alert = UIAlertView(title: "", message: "bla", delegate: nil, cancelButtonTitle: "OK") alert!.show() return true } } 

How to do it right? :)

+9
swift uialertview uialertcontroller
Jun 04 '14 at 14:41
source share
7 answers

You should do it like this:

 let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Button", style: UIAlertActionStyle.Default, handler: nil)) self.presentViewController(alert, animated: true, completion: nil) 
+20
Jun 04
source share

Even if UIAlertView depreciates in iOS8, you can avoid using it, but not through its init function. For example:

  var alert = UIAlertView() alert.title = "Title" alert.message = "message" alert.show() 

At least this is the only way so far to successfully use UIAlertView . I'm not sure how safe this is.

+15
Jun 04 '14 at
source share

This is what I used to create the alert popup in swift.

 let myAlert = UIAlertView(title: "Invalid Login", message: "Please enter valid user name", delegate: nil, cancelButtonTitle: "Try Again") myAlert.show() 
+1
Aug 4 '14 at 16:08
source share
 var alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil)) self.presentViewController(alert, animated: true, completion: nil) 

To process actions:

 alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { action in switch action.style { case .Default: println("default") case .Cancel: println("cancel") case .Destructive: println("destructive") } })) 
0
Nov 10 '14 at 10:07
source share

I was able to successfully show the UIAlertView using this code:

 var alert = UIAlertView() alert.title = "Title" alert.message = "Message" alert.addButtonWithTitle("Understood") alert.show() 

The code "alert.addButtonWithTitle (" Understood ")" adds a button for the user to click after they read the error message.

Hope this helps you.

0
Mar 05 '15 at 14:49
source share

Xcode 10 Swift 4.2

  let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertController.Style.alert) alert.addAction(UIAlertAction(title: "Button", style: UIAlertAction.Style.default, handler: nil)) self.present(alert, animated: true, completion: nil) 
0
Mar 25 '19 at 10:44
source share
 let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertController.Style.alert) alert.addAction(UIAlertAction(title: "Ok", style: UIAlertAction.Style.default, handler: nil)) self.present(alert, animated: true, completion: nil) 
0
May 18 '19 at 9:17
source share



All Articles