2011-08-07 128 views
0

我是iphone新手,我需要一些指導推視圖。我有以下應用場景「按下按鈕 - >切換視圖(包含一個表格) - >按表格單元 - >切換視圖」。如何推iphone的觀點?

切換當我按下我使用下面的代碼的按鈕:

MapView *screen = [[MapView alloc] initWithNibName:nil bundle:nil]; 
screen.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
[self presentModalViewController:screen animated:YES]; 
[screen release]; 

然後推另一種看法,我想使用此代碼(但它不工作 - 和IM問爲什麼?)

Newclass *nextController = [[Newclass alloc] initWithItem:theItem]; 
    [self.navigationController pushViewController:nextController animated:YES]; 
    [nextController release]; 
+1

你正在使用self.navigationController我猜你的mapview沒有導航控制器 – Matt

回答

2

你想從你的MapView推這個視圖?看起來你沒有一個UINavigationController來推動視圖控制器。

更新代碼的第一部分,將MapView放入UINavigationController中,然後將其他視圖放到第二部分代碼中。

MapView *screen = [[MapView alloc] initWithNibName:nil bundle:nil]; 
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:screen]; // this puts the MapView onto navigation controller 
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; // you will present the navController instead of screen so change it's modalTransitionStyle 
[self presentModalViewController:navController animated:YES]; // present it 
[screen release]; 
[navController release]; // don't forget to release