How to call initWith… in swift

后端 未结 4 723
忘掉有多难
忘掉有多难 2021-01-25 07:52

I have a an objective-c class (RDAlertView) which create an Alert (UIAlertView for ios < 8 and UIAlertController for ios >=8 )

Here is the code in Object

相关标签:
4条回答
  • 2021-01-25 08:11
    UIAlertView.showWithTitle("Hello", message: "Hello World", cancelButtonTitle: "Okay") { alertView, buttonIndex in
    
    // Do something when the alert view is clicked
    
    let anAlertView = UIAlertView(title: "Choice", message: "Pick one", cancelButtonTitle: "No", otherButtonTitles: "Yes", "Maybe")
    
    anAlertView.showWithCompletion { alertView, buttonIndex in
    
    switch buttonIndex
    {
       case 1: println("Yes")
       case 2: println("Maybe")
       default: println("No")
    }
    }
    
    0 讨论(0)
  • 2021-01-25 08:16

    UIAlertView is deprecated in iOS 8.

    You can show an alert with this code:

    var alert = UIAlertController(title: "Alert", message: "test", preferredStyle: UIAlertControllerStyle.Alert)
    
    alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
    
    self.presentViewController(alert, animated: true, completion: nil)
    
    0 讨论(0)
  • 2021-01-25 08:24

    These methods are treated like constructors. You can call them like this:

    var alert = RDAlertView("notification", message:"message", completion:nil, cancelButtonTitle:"Cancel", otherButtonTitles:nil)
    alert.show()
    

    Caveat: written without an IDE, careful of syntax errors / typos

    0 讨论(0)
  • 2021-01-25 08:33

    I think this is what you need:

    var alert = RDAlertView(title: "Notification", message: "message", completion: nil, cancelButtonTitle: "OK", otherButtonTitles: nil)
    alert.show()
    

    Hope It will help.

    0 讨论(0)
提交回复
热议问题