0
我想以編程方式導航一些視圖控制器。我已經在頭文件中添加了UINavigationControllerDelegate ...但是當點擊按鈕時視圖沒有被推出...任何人都可以告訴我我做錯了什麼嗎?UINavigationController推送不正確
-(void)nextPage
{
NSLog(@"1234");
infoViewController* info = [[infoViewController alloc] init];
[self.navigationController pushViewController:info animated:YES];
info = nil;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.delegate = self;
startFutureView = [[UIView alloc] initWithFrame:CGRectMake(160, 0, 320, 548)];
startFutureView.backgroundColor = [UIColor redColor];
[self.view addSubview:startFutureView];
startPastView = [[UIView alloc] initWithFrame:CGRectMake(-160, 0, 320, 548)];
startPastView.backgroundColor = [UIColor blueColor];
[self.view addSubview:startPastView];
startInfoBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
startInfoBtn.frame = CGRectMake(80, 137, 180, 180);
[startInfoBtn addTarget:self action:@selector(nextPage) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:startInfoBtn];
// Do any additional setup after loading the view, typically from a nib.
}
變化登錄self.navigationController的的NSLog 。它是零嗎? – wattson12 2013-04-27 17:54:17
只是將navcontrollerdelegate添加到頭文件是不夠的。你是否創建了navigationController的實例?它被分配給窗口的rootViewController嗎?如果您嘗試推送的viewController不是UINavigationController的rootviewcontroller,則不會發生任何事情。添加更多關於你的AppDelegate和ViewController的代碼將會有所幫助 – 2013-04-27 17:59:25