2012-07-20 76 views
1

我目前正在研究一個應用程序,該應用程序從爛番茄API中檢索電影列表並將它們顯示在表中。我想要一個UIViewController顯示一旦我點擊一行,所以我可以顯示一個詳細的頁面。試圖將UIViewController推送到UITableViewController

這裏是我爲我的didSelectRowAtIndexPath的代碼。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath 
{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; 
    //UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:self]; // This line of code throws an exception for some reason. 
    [self.navigationController pushViewController:detailViewController animated:YES]; 
} 

這可能是我沒有睡了很長一段時間,但我不能爲我的生活找出我要去哪裏錯了。

PS。我正在使用弧。

+0

檢查導航控制器是否爲NSLog – doNotCheckMyBlog 2012-07-20 12:36:41

+0

您確定您的導航控制器已初始化? – EsbenB 2012-07-20 12:35:32

+0

@RehatKathuria,只需檢查它是否爲零,然後告訴我們你找到了什麼 – doNotCheckMyBlog 2012-07-20 12:39:57

回答

2

您確定您的導航控制器已初始化?

如果沒有您的正確缺失的地方是這樣的,你構建你的UIViewController

MyVc = [[MyVC alloc] initWithNibName:@"MyVC" bundle:nil]; 
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:myVc]; 
[_window addSubview:navCon.view]; 
+0

我已經啓動了導航控制器,導航欄已經顯示出來,但NSLog告訴我它是零。我很困惑。 – 2012-07-20 13:13:35

+0

聽起來很奇怪。也許你仍然將你的舊觀點加入_window ?.您應該只向_window添加單個視圖,即navCon的視圖。 – EsbenB 2012-07-20 14:00:36

0

寫AppDelegate.h這些屬性文件

@property (strong, nonatomic) YourFirstViewController *yourFirstController; 
@property (nonatomic, retain) UINavigationController *navigationControl; 

寫的AppDelegate此代碼。 m文件

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    { 

     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
     self.yourFirstViewController = [[YourFirstViewController alloc] initWithNibName:@"YourFirstViewController" bundle:nil]]; 
     navigationController = [[UINavigationController alloc] initWithRootViewController:self.yourFirstViewController]; 
     [self.window addSubview:[navigationController view]]; 
     [self.window makeKeyAndVisible]; 
     return YES; 
    } 

我認爲這對我有幫助喲ü。

相關問題