开发者

is it a good idea to call viewdidload in a method?

I was just curious weather it is a good idea to call viewdidload a meth开发者_运维问答od like in an ibaction or something of that kind.

thanks, TC


Check:
UIViewController Class Reference

viewDidLoad

This method is called after the view controller has loaded its associated views into memory. This method is called regardless of whether the views were stored in a nib file or created programmatically in the loadView method. This method is most commonly used to perform additional initialization steps on views that are loaded from nib files.

The viewDidLoad method is automatically triggered.
Generally there is no need to trigger viewDidLoad yourself.
If you need to run specific code both after loading and button-click, do this:

- (void)viewDidLoad {
    [self specificFunction];
}

- (IBAction)theButton:(id)sender {
    [self specificFunction];
}


- (void)specificFunction {
    // This code wil run after the view has been loaded
    // and when the user clicks the button
}


The disadvantage of calling ViewDidLoad is , the superclass methods would be called as it has [super viewDidLoad], which is not a good idea . It's better to have a separate methods and call them whenever necessary .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜