Do I always have to call [super viewDidLoad] in the -viewDidLoad method?

前端 未结 8 800
[愿得一人]
[愿得一人] 2020-11-27 16:18

In Apple\'s scrollView example they don\'t call that. I always thought that\'s a must. Why should I call that anyways?

相关标签:
8条回答
  • 2020-11-27 16:45

    If you are overriding the method you should still call the method in the super. Even if the super class is not doing anything with it today, Apple might one day change the implementation and your code will mysteriously stop working. If you really don't need to do anything in that method, leave it out of your code entirely, and the super's method will run as usual, without any intervention on your part.

    0 讨论(0)
  • 2020-11-27 16:47

    Although in xCode 7 Beta/Swift 2 super.viewDidLoad won't compile. The error says it's only available in osx 10.10 and the auto-fix does this

    if #available(OSX 10.10, *){
    super.viewDidLoad()}
    else
    {
    // Fallback on earlier versions
    }
    // My code
    }
    
    0 讨论(0)
提交回复
热议问题