ios - Double Initialization Of UIViewController's Subclass Member in Swift -


I wanted to create a custom container view controller and some members in the subclass of UIViewController added up.

  self.window = UIWindow ?: When I tried to init the app representatives using the following code limits (frame :. UIScreen.mainScreen ()) self.window .rootViewController = CustomContainerViewController ( ) Self. Window? All members were started twice in Mckyke and Visible ()   

Custom Container Week Controller .

The CustomContainerViewController code:

  class CustomContainerViewController: (: NSCoder coder aDecoder) {super UIViewController {to tabBar = CustomTabBar (in ) Override init () {super.init ()} init is required. init (Coder: aDecoder)} override the init (nibName nibNameOrNil: string? bundle nibBundleOrNil: NSBundle?) {super.init (nibName: nibNameOrNil?, bundle: nibBundleOrNil)}}   < P> Here is the code of  custom tabbar:  
  class custombars: UIView {override init () {println ("init") super.init ()} override init (frame: Sijiartiaks) {println ( "initWithFrame:") super.init (frame: frame)} requi red init (coder aDecoder in: NSCoder) {println ( "initWithCoder:") super.init (Coder : ADecoder)}}   

whenever you want to CustomCon The app representative, using the code already described init by using the tinerViewController , always prints "init", "initWithFrame" twice.

Used incorrectly named originator

UIViewController Only a named starter is init (nibName nibNameOrNil: string ?, bundle nibBundleOrNil: NSBundle?)

As your comment

designated initializer if you UIViewController subclass, you should call the super implementation of this method, even if you are not using a NIB. (As a convenience, the default init method can do this for you, and this method specifies zero for both arguments.) In specified NIB, the owner of the file must set proxy to its view controller subclass, the view Outlet is linked to the main scene. If you call this method with zero nibb name, then this class' load veui system will try to load a niB The name of which is similar to your visual controller class. If there is really no such NIB, then you need either a call-set view: First-visit is implemented, or the program has to override the review method to set your ideas.

So whenever you override init () the method UIViewController , once you make a super call, code> UIViewController implementation init (nibName nibNameOrNil: String?, bundled Nibbndl Ornel: Ansbindl?) so on your behalf all the members in your sub-class of UIViewController Was started twice

To resolve this problem, use the following code in app rep

  self.window = UIWindow (frame: UIScreen.mainScreen () range) self .window .rootViewController = CustomContainerViewController? (NibName: zero, bundle: zero) self.window .makeKeyAndVisible ()    and never override this method in  init ()  method  UIViewController  or subclasses.   

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -