2010-07-15 32 views
1

我被困在試圖從three20中彈出一個TTPhotoViewController。起初它沒有帶後退按鈕,但我現在已經實現了它,試圖彈出的視圖沒有運氣。下面是我的代碼片段:如何彈出TTPhotoViewController?

按鈕(這工作) -

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:TTLocalizedString(@"Back", @"Back to Albums") style:UIBarButtonItemStyleBordered target:self action:@selector(popView)]; 

-popView(方法被調用,但聲明不工作) -

- (void) popView { 
    [self.navigationController popViewControllerAnimated:NO]; 
} 

感謝

更新0 -

這是ttphotoviewcontroller在其init中的代碼(我檢查了tha t時的程序運行此) -

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { 
     self.navigationItem.backBarButtonItem = 
     [[[UIBarButtonItem alloc] 
     initWithTitle: 
     TTLocalizedString(@"Photo", 
     @"Title for back button that returns to photo browser") 
     style: UIBarButtonItemStylePlain 
     target: nil 
     action: nil] autorelease]; 

     self.statusBarStyle = UIStatusBarStyleBlackTranslucent; 
     self.navigationBarStyle = UIBarStyleBlackTranslucent; 
     self.navigationBarTintColor = nil; 
     self.wantsFullScreenLayout = YES; 
     self.hidesBottomBarWhenPushed = YES; 

     self.defaultImage = TTIMAGE(@"bundle://Three20.bundle/images/photoDefault.png"); 
    } 

return self; 
} 

它已經加入了後退按鈕,但可惜這段代碼也不會添加一個按鈕,導航欄我。

回答

1

如果您的操作與Catalog示例中的操作類似,那麼您只需將其添加到根視圖控制器中即可(例如,不在視圖中,該視圖在被推入堆棧後會顯示,但在父視圖中視圖)。

此操作與普通的iPhone UINavigationController操作沒有區別。

- (id)init { 
    if (self = [super init]) { 

    // setup back button for nav controller 
    self.navigationItem.backBarButtonItem = 
     [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered 
     target:nil action:nil] autorelease]; 

    } 
} 

當新視圖被壓入堆棧時,它將使用該返回按鈕返回。您不必調用popView或其他任何東西。注意我正在使用backBarButtonItem,而您使用的是leftBarButtonItem(只有在您使用自定義後退按鈕時才使用)。

欲瞭解更多信息,請閱讀的this document

+0

感謝您的回覆。我試過了,它看起來沒有工作..我已經更新了我的問題,以包含更多的細節。 – jmont 2010-07-15 22:19:34

+0

您是從TTNavigator繼承還是從您自己的導航繼承?你是對的,因爲它沒有在那裏添加後退按鈕(我只是試着註釋掉所有的代碼,它仍然從某處獲得後退按鈕)。但是,當我在代碼中搜索「BarButtonItem」時,我沒有找到其他地方。我不知道他是如何添加這些文件的。 – iwasrobbed 2010-07-15 23:02:05

+0

在我的項目中,我使用'Catalog'示例中的'MockPhotoSource'和'PhotoTest1Controller',它自動爲我創建後退按鈕(並彈出視圖) 。他可能只是讓它繼承自Apple的導航類,因爲我可以使用上面的代碼更改後退按鈕文本。 – iwasrobbed 2010-07-15 23:03:06

0

「更新導航欄中的」節之前你推TTPhotoViewController添加此代碼。

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

    self.navigationItem.backBarButtonItem = nil; 
    self.navigationItem.backBarButtonItem = backButton;