Objective c 如何正确地更改实际视图控制器?在加载的视图父视图上,presented和presentingViewController为空

Objective c 如何正确地更改实际视图控制器?在加载的视图父视图上,presented和presentingViewController为空,objective-c,xcode,cocoa,ios6,parentviewcontroller,Objective C,Xcode,Cocoa,Ios6,Parentviewcontroller,我的iOS iPad应用程序具有以下结构: RootViewController:登录 @属性uitabar*main(登录成功后加载) 在appDelegate上,我有两个属性:window和login。在第一个窗口上,我加载ui窗口,在另一个窗口上加载LoginViewController(UIViewController)。并将登录设置为RootViewController 登录时,我有一个名为“main”的属性,键入为MainController(扩展UITabbarContro

我的iOS iPad应用程序具有以下结构:

  • RootViewController:登录
    • @属性uitabar*main(登录成功后加载)
在appDelegate上,我有两个属性:window和login。在第一个窗口上,我加载
ui窗口
,在另一个窗口上加载
LoginViewController(UIViewController)
。并将登录设置为RootViewController

登录时,我有一个名为“main”的属性,键入为
MainController
(扩展
UITabbarController

成功登录后,我使用上面的代码加载main:

[_main setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:_main animated:YES completion:nil];
MainController已在viewDidLoad方法中加载。我有两点:

我需要将self设置为MainController的代理

这是我的MainController viewDidLoad方法的开始:

[super viewDidLoad];
[self setDelegate:self];
NSLog(@"Parent view controller is: %@", [self parentViewController]);
NSLog(@"Presented view controller is: %@", [self presentedViewController]);
NSLog(@"Presenting view controller is: %@", [self presentingViewController]);
此日志为:

2013-01-20 21:23:53.180 MyApp[6304:11303] Parent view controller is: (null)
2013-01-20 21:23:53.181 MyApp[6304:11303] Presented view controller is: (null)
2013-01-20 21:23:53.182 MyApp[6304:11303] Presenting view controller is: (null)
我是否使用正确的方式呈现viewController?或者单击按钮或登录后显示视图? 少了什么?我是否正确使用视图层次结构

是否需要一个属性来包含将显示的控制器


从现在起我很感激

您是否自己编写了应用程序代理和其他控制器的代码?如果是这样的话,那么因为您还没有发布其余的代码,所以我只能说初始化所有视图控制器

YourViewControllerNameHere = [[ViewControllerType alloc] init];
或者如果您有一个nib/xib/storyboard文件,那么

    YourViewControllerNameHere = [[ViewControllerType alloc] initWithNibName:youInterfaceFileNameHereWithoutFileType bundle:nil];

亚历克斯,我被他们骗了。它们正确加载和显示,只是在重新运行时没有定义parentViewController。