hok*_*rus 0 xcode objective-c uiviewcontroller
我正在尝试创建一个容器视图控制器来将UINavigationController和自定义UIViewController一起保存在屏幕上.
我把它放在一个测试程序中,它运行得很好,但是当我尝试在我的实际项目中实现它时,包含View控件的外观方法永远不会被调用.
工作测试:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MasterStatusViewController *master = [[MasterStatusViewController alloc] init];
[self.window setRootViewController:master];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
InventoryViewController *newInventory = [[InventoryViewController alloc] init];
self.navigation = [[UINavigationController alloc] initWithRootViewController:newInventory];
self.statusRibbon = [[StatusBarViewController alloc] initWithNibName:@"StatusBarViewController" bundle:nil];
[self addChildViewController:self.navigation];
self.navigation.view.frame = self.navigationView.frame;
[self.view addSubview:self.navigation.view];
[self.navigation didMoveToParentViewController:self];
[self addChildViewController:self.statusRibbon];
self.statusRibbon.view.frame = self.ribbonView.frame;
[self.view addSubview:self.statusRibbon.view];
[self.statusRibbon didMoveToParentViewController:self];
}
Run Code Online (Sandbox Code Playgroud)
失败的项目:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
MasterViewController *master = [[MasterViewController alloc] init];
self.centerController = master;
[self.window setRootViewController:master];
[self.window makeKeyAndVisible];
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
LoginViewController *login = [[LoginViewController alloc] init];
self.navigation = [[UINavigationController alloc] initWithRootViewController:login];
self.statusRibbon = [[StatusRibbonViewController alloc] init];
[self addChildViewController:self.navigation];
self.navigation.view.frame = self.navigationView.frame;
[self.view addSubview:self.navigation.view];
[self.navigation didMoveToParentViewController:self];
[self addChildViewController:self.statusRibbon];
self.statusRibbon.view.frame = self.ribbonView.frame;
[self.view addSubview:self.statusRibbon.view];
[self.statusRibbon didMoveToParentViewController:self];
}
Run Code Online (Sandbox Code Playgroud)
视图排列正确并按预期执行,但外观方法永远不会被调用.我很困惑.手动调用方法似乎不是一种解决方案,因为这些调用也没有通过.
编辑:通过外观方法我的意思是viewWillAppear,viewDidAppear,et al.
第二次编辑:
~snip~
第三次编辑:经过进一步检查,我认为没有调用外观生命周期方法的原因是因为它们也没有在容器视图控制器上调用.我补充道
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"MasterViewController VIEW WILL APPEAR");
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@"MasterViewController VIEW DID APPEAR");
}
Run Code Online (Sandbox Code Playgroud)
在masterViewController并没有什么,因为某些原因,他们永远不会被调用.
解决了它.我不知道为什么没有调用主外观方法,xcode的一些清理似乎解决了这个问题.
但是,这些方法仍未转发给我的其他视图控制器.然后我偶然发现了这个链接,并了解到无论如何都要向他们转发外观.我能够通过添加以下内容来修复它:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigation beginAppearanceTransition: YES animated: animated];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.navigation endAppearanceTransition];
}
-(void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigation beginAppearanceTransition: NO animated: animated];
}
-(void) viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self.navigation endAppearanceTransition];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3090 次 |
| 最近记录: |