我们都知道viewDidLoad是在视图加载时调用,但是具体是何时调用,看下面代码就清楚了
UIViewController.m的部分代码
- (BOOL)isViewLoaded { return (_view != nil); } - (UIView *)view { if ([self isViewLoaded]) { return _view; } else { const BOOL wereEnabled = [UIView areAnimationsEnabled]; [UIView setAnimationsEnabled:NO]; [self loadView]; //当_view为nil时,首先调用loadView初始化_view,紧接着调用viewDidLoad [self viewDidLoad]; [UIView setAnimationsEnabled:wereEnabled]; return _view; } } - (void)loadView { self.view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)]; } - (void)viewDidLoad { }
时间: 2024-10-07 14:59:47