2011-05-20 96 views

回答

7

检查:
UIViewController Class Reference

viewDidLoad中

此方法的视图 控制器之后调用加载其相关联 视图到内存中。此方法调用 ,无论视图 是存储在nib文件中还是以编程方式在loadView 方法中创建 。此方法最常用于对从nib文件加载的视图 执行附加的 初始化步骤 。

viewDidLoad方法被自动触发。
一般不需要自己触发viewDidLoad
如果需要运行特定的代码加载和两个后按钮点击,这样做:

- (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 
} 
0

调用ViewDidLoad的缺点是,超类的方法将被调用,因为它具有[super viewDidLoad],这是不是一个好想法。 最好有一个单独的方法,并在必要时调用它们。

相关问题