Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAlertController subclass issue swift

I want to create a UIAlertController's subclass but I'm going crazy because I have problem with constructor, this is my subclass:

class loginAlert :  UIAlertController {

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

    }

}

I think that this subclass must have the constructor : UIAlertController(title: String, message: String, preferredStyle: UIAlertControllerStyle) , because it's a subclass of UIAlertController , but when I do

loginAlert(title: "test", message: "test", preferredStyle: .Alert)

I get error , why where Do I wrong?

like image 395
gino gino Avatar asked Nov 24 '15 22:11

gino gino


1 Answers

From the UIAlertController Class Reference:

Subclassing Notes The UIAlertController class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

You can create a view controller whose view contains transparency and whose UIModalPresentationStyle is .OverCurrentContext and UIModalTransitionStyle is .CrossDissolve for a very similar effect.

Or you can write an extension on UIAlertController that can add methods that need to be shared across classes (e.g. a method that presents a reoccurring alert). For more information about extensions, see here.

like image 103
beyowulf Avatar answered Sep 24 '22 06:09

beyowulf