Добрый вечер,IOS UINavigationController, pushViewController не работает
В настоящее время у меня есть два UIViewControllers. Мой AppDelegate выглядит следующим образом
- (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;
}
ViewController выглядит следующим образом:
- (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];
}
При нажатии на кнопку информация, которая была добавлена к правой стороне на панели навигации, я хочу, чтобы перейти к secondView. Это, однако, не происходит, потому что navigationController регистрируется как ноль! Что мне здесь не хватает?
Любая помощь действительно оценена!
Благодарим за подсказку! Я изменил код, но он не работает! Он говорит, что ожидаемый rootViewCintoller в конце запуска приложения – Pascal
ах вам нужно установить rootViewController в окне – railwayparade
self.window.rootViewController = nc; – railwayparade