我想測試viewDidLoad中和的loadView之間的區別,所以我創建一個單一視圖的應用程序和超過設定的didFinishLaunchingWithOptions如流:viewDidLoad中和的loadView問題
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
viewController = [[MyViewController alloc] init];
// viewController.view.backgroundColor = [UIColor redColor];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
在我MyViewController的M檔是流動:
#import "MyViewController.h"
@interface MyViewController()
@end
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"%@",self.view);
self.view.backgroundColor = [UIColor redColor];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)loadView {
self.view = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
}
@end
但loadView方法或viewDidLoad沒有被調用。爲什麼?但是當我在didFinishLaunchingWithOptions取消註釋時,他們都被調用。
它工作,我也找到它了。謝謝你的回答。 – Scott
我可以說,當我們使用self.view,如果視圖爲零,方法loadView會調用? – Scott
你說得對。 'viewDidLoad'將在'loadView'之後執行。 – Bannings