2011-08-11 191 views
1

我有一個分割視圖應用程序,允許用戶選擇並顯示所選圖像的縮略圖。我已經使用Interface Builder在detailViewController中放置了一個UIButton。當按下此按鈕時,我希望將其更改爲圖像的全屏視圖。我已經建立了一個新的視圖控制器,稱爲FullViewController,並認爲我已經連接了一切。問題是導航控制器爲空。我調整了AppDelegate.m以下幾點:導航控制器爲空

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
// Override point for customization after app launch. 
// Set the split view controller as the window's root view controller and display. 
self.window.rootViewController = self.splitViewController; 
UINavigationController *nvcontrol =[[UINavigationController alloc] initWithRootViewController:fullViewController]; 
[window addSubview:nvcontrol.view]; 
[self.window makeKeyAndVisible]; 
return YES; 
} 

這是DetailViewController.m功能按鈕被按下時調用。導航控制器在這裏顯示爲空。

//Function called when button is pressed - should bring up full screen view 
- (IBAction) pressFullViewButtonFunction: (id) sender{ 
//viewLabel.text = @"Full View";  
if (fullViewController == nil){ 
    FullViewController *fullViewController = [[FullViewController alloc] initWithNibName:@"FullViewController" bundle:[NSBundle mainBundle]]; 
    NSLog(@"fullViewController is %@", fullViewController); 
    self.fullViewController = fullViewController; 
} 
NSLog(@"self.navigationController is %@",self.navigationController);//this is null 
[self.navigationController pushViewController:self.fullViewController animated:YES]; 

}

我不知道如何解決這個問題。我已經嘗試在AppDelegate的幾行中添加,但是當它運行時,根視圖中的表格不顯示,並且不再適當地在縱向和橫向視圖之間切換。

我有其他代碼可以隨時使用,如果這有助於澄清。請讓我知道! 謝謝。

回答

1

從您發佈它無法識別該問題的代碼,而是兩個爲self.navigationController常見的原因是零是:

  1. 你沒有上推對象後面self導航控制器第一名;事實上似乎是這樣,因爲導航控制器被添加爲分割視圖控制器的子視圖;可能你的意思是相反...不確定...

  2. (子情況1)您使用presentViewControllerModally顯示self後面的對象。

當我說「的背後self對象」我的意思是,其中pressFullViewButtonFunction定義的類的實例。

如果您需要更多的幫助,其中後你推到導航控制器你的控制器代碼...

在一個側面說明,如果你這樣做:

UINavigationController *nvcontrol =[[UINavigationController alloc] initWithRootViewController:fullViewController]; 

nvcontrol不一個伊娃,那麼你有一個泄漏。

希望這有助於...