0
おはよう、IOS UINavigationController、pushViewController not working
私は現在2つのUIViewControllerを持っています。ナビゲーションバーの右側に追加された情報ボタン、をクリックすると
- (void)loadView {
self.view = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.title = @"Master View";
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self action:@selector(switchView:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
}
- (void)switchView:(id)obj {
if(![self navigationController])
NSLog(@"navigationController IS NIL!!!");
if(!_secondView)
_secondView = [[secondViewController alloc] init];
[self.navigationController pushViewController:_secondView animated:YES];
}
、私はに切り替えたい:私appDelegateはViewControllerを、このようになります。この
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
struct CGRect rect = [[UIScreen mainScreen] bounds];
rect.origin.x = rect.origin.y = 0.0f;
_viewController = [[sandboxViewController alloc] init];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:_viewController];
_window = [[UIWindow alloc] initWithFrame:rect];
[_window makeKeyAndVisible];
[_window addSubview:nc.view];
return YES;
}
のように見えますsecondView。しかし、これは、navigationControllerがnilとしてログを記録するので起こりません!私はここで何が欠けていますか?
本当にありがとうございます。
ヒントありがとうございます!私はコードを変更しましたが、機能しません!それは、アプリケーションの起動の最後にrootViewCintollerが期待していると言う。 – Pascal
あなたはウィンドウにrootViewControllerを設定する必要があります。 – railwayparade
self.window.rootViewController = nc; – railwayparade