2011-02-23 211 views
1

我已經創建了一個基於導航的應用程序模板的項目,並做了一些工作,並運行它。按鈕不顯示在導航欄項

我想如果我觸摸一個單元格,新的視圖會顯示出來,並且新的圖標(它將返回按鈕)也會顯示在導航欄項目上。

但由於某種原因,「後退按鈕」不會自動添加。有什麼問題?

以下是我的代碼。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    // Navigation logic may go here -- for example, create and push another view controller. 
    MessageView *detailViewController = [[MessageView alloc] initWithNibName:@"MessageView" bundle:nil]; 

    NSDictionary* aMessage = [m_tableData objectAtIndex:indexPath.row]; 
    detailViewController.m_message = [[NSDictionary alloc] initWithDictionary:aMessage]; 

    // Pass the selected object to the new view controller. 
    [self.navigationController pushViewController:detailViewController animated:YES]; 
    [detailViewController release]; 
} 
+0

它是您推入導航控制器的視圖(MessageView)嗎?你只能推UIViewController而不推UIView – Nevin 2011-02-23 01:56:03

回答

7

你可能沒有給你父控制器(在viewDidLoad中或viewWillAppear中只是self.title = @「我的名字」)的目標。這就是後退按鈕默認填入的內容,所以如果你沒有給它起個名字,你就不會得到後退按鈕。

+0

謝謝。它現在有效。 – SeniorLee 2011-02-23 14:20:04

+0

偉大的提示!你說它被「默認」填充。只是好奇是否意味着你可以給「後退按鈕」一個與控制器本身不同的標題?謝謝!!! – jpswain 2011-07-18 19:23:39

+1

是的,你可以製作你自己的按鈕(至少在父母),一旦被稱爲後退按鈕顯然是固定的。例如,self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@「Back」 style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease]; – mackworth 2011-07-19 01:54:05

1

您在說MessageView是從UIView繼承而來的。但我認爲如果沒有問題推入導航控制器,那麼它將是UIViewController的子類。

有一些原因,不顯示後退按鈕: -

1)由於麥克沃思告訴你沒有給您從中瀏覽任何所有權。

2.)您的導航欄的後退按鈕屬性設置爲隱藏。

否則返回按鈕應該出現在導航欄上。

+0

感謝您的回答。但我不能接受多於一個的答案;(剛剛給了它第一個答案對不起, – SeniorLee 2011-02-23 14:20:58

1

看來你沒有設置你的導航欄標題的視圖從正在導航...

一旦你默認設置導航欄的標題,它會顯示你的後退按鈕

在ViewDidLoad或ViewWillAppear中使用它。

self.navigationItem.title = @「在此設置您的標題」;

+0

謝謝你的答案,但我不能接受多於一個答案;(剛剛給了它首先回答對不起。 – SeniorLee 2011-02-23 14:22:04