search

Home  >  Q&A  >  body text

objective-c - 在创建UIViewController类的实例时,是否一定要使用-initWithNibName:bundle:方法

比如新建一个MyViewController,如果不重写initWithNibName:bundle:方法,在其他的类中也可以直接使用:

MyViewController *controller = [[MyViewController alloc] init]

重写这个方法除了具有修改功能外,还有什么作用?

迷茫迷茫2766 days ago312

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-24 09:13:47

    It’s okay without rewriting. Because MyViewController是继承自UIViewController, if it is not overridden, this method of the parent class will be automatically called.

    Rewriting is usually done to do some initialization processing. In fact, the initialization processing is usually placed in viewDidLoad. So what I see is that this method is generally not rewritten.

    reply
    0
  • Cancelreply