2011-03-19 113 views
2

我有一個像這樣調用全屏modalView:iPhone - 導航欄後退按鈕項目沒有響應

PreferencesController *nextWindow = [[[PreferencesController alloc] initWithNibName:@"Preferences" bundle:nil] autorelease]; 
UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:nextWindow] autorelease]; 
[self presentModalViewController:navController animated:YES]; 

然後從這個modalView我把另一種觀點認爲:

MyController *nextWindow = [[[MyController alloc] initWithNibName:@"tmp" bundle:nil] autorelease]; 
    [self.navigationController pushViewController:nextWindow animated:YES]; 

在這個新的控制器,我有這個viewDidLoad:

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.title = @"Borders"; 
    self.navigationController.navigationBarHidden = NO; 
} 

leftBarButtonItem不活動,我的意思是觸摸它不突出顯示它,也不會回到以前的視圖。

我的視圖全屏顯示,[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];在應用程序初始化時調用。

navigationBar框架是0,0,320,44。
導航欄超級視圖框架爲0,0,320,480。
viewController視圖框架是0,0,320,436。

我試着打電話在viewDidLoad self.navigationController.navigationBar.userInteractionEnabled = YES;self.navigationItem.leftBarButtonItem.enabled = YES;沒有效果。

會發生什麼?

編輯:
我self.navigationController.navigationItem.backBarButtonItem爲零。 self.navigationController.navigationItem不是無

+0

你有什麼其他的代碼在你的viewDidLoad中進行? – 2011-03-19 15:35:22

+0

@Wayne Hartman:這就是整個代碼。 – Oliver 2011-03-19 15:36:06

+0

這是否只發生在這個特定的視圖控制器(MyController)上,還是與從你的應用程序的這一點上推到導航控制器堆棧上的任何其他視圖控制器的行爲相同?就我所知,我的意思是你發佈的代碼看起來很好。 – hennes 2011-03-19 15:56:36

回答

0

我找到了解決方案。 問題在於第一個視圖是從疊加層調用的,而不是來自選擇器。 保持在摘取一個參考到覆蓋,並要求從它的視圖解決了這個問題:

從覆蓋:

[self.picker presentModalViewController:navController animated:YES]; 

工作

代替:

[self presentModalViewController:navController animated:YES]; 
1

無論何時這種無響應發生在我身上,總是因爲構架問題。即NavigationController的超視圖小於NavigationController的視圖。我知道你說所有內容都設置爲全屏,但是我會通過爲層次結構中的每個視圖開啓「clipsSubviews」來驗證所有內容實際上都是全屏。

+0

我試過剪輯子視圖,並試圖強制self.wantsFullScreenLayout = YES; self.navigationController.wantsFullScreenLayout = YES;在viewDidLoad中,並沒有改變這個問題。 – Oliver 2011-03-20 00:29:39

+0

navigationBar框架爲0,0,320,44,導航欄超級框架框架爲0,0,320,480。該controlelrsview框架是0,0,320,436 – Oliver 2011-03-20 00:36:24

0

我只是有這個問題,我不知道爲什麼這個工作,但的,而不是做:

UIBarButtonItem *backButton = 
[[[UIBarButtonItem alloc] initWithTitle:@"Back" 
            style: UIBarButtonItemStyleBordered 
           target:nil 
           action:nil] autorelease]; 

self.navigationItem.leftBarButtonItem = backButton; 

我取代了第二行以

self.navigationController.navigationItem.leftBarButtonItem = backButton; 

這對我的作品。

+0

謝謝,但我從來沒有創建此按鈕。它由NavigationController自動生成。所以我不能在這種情況下應用你的解決方案。 – Oliver 2011-03-20 00:39:14

+0

事件,如果我在viewDidLoad中self.navigationController.navigationItem.leftBarButtonItem =力[[[的UIBarButtonItem頁頭] initWithTitle:@ 「返回」 風格:UIBarButtonItemStyleBordered 目標:無 行動:無]自動釋放]。沒有任何變化,按鈕名稱也不會改變。 – Oliver 2011-03-20 00:41:44

+0

@Oliver你確定你引用了正確的leftBarButtonItem嗎?我認爲這是前一個控制器設置leftBarButtonItem的動作,所以如果你有控制器1和2,那麼將後退按鈕設置爲2必須在1中完成。 – streamba 2011-03-20 00:45:59