0

我正在使用故事板並開發iPhone應用程序並使用導航控制器。使用默認導航欄文本

當我實現它時,我注意到它使用視圖的名稱而不是使用默認的「後退」文本,有沒有辦法強制它使用「後退」?

感謝

回答

0

當你出現在UINavigationController,想必在你的應用程序的委託,使應用程序的委託也是導航控制器的委託。然後查看被彈出並推視圖控制器:

AppController.h

#import <UIKit/UIKit.h> 

@interface AppController.h : NSObject 
<UIApplicationDelegate, UINavigationControllerDelegate> 
{ 
    UIWindow *window; 
    UINavigationController *viewController; 
} 
/* MARK: Interface Outlets */ 
@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet UINavigationController *viewController; 
@end 

AppController.h

#import "AppController.h" 

@implementation AppController.h 
/* MARK: Init and Dealloc */ 
- (void)dealloc { 
    self.window = nil; 
    self.viewController = nil; 

    [super dealloc]; 
} 

/* MARK: Interface Outlets */ 
@synthesize window, viewController; 

/* MARK: Application Delegate */ 
- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    assert(self.window != nil); 
    assert(self.viewController != nil); 

    self.viewController.delegate = self; 

    /* other initialization */ 

    [self.window makeKeyAndVisible]; 

    return YES; 
} 

/* MRK: Navigation Controller Delegate */ 
- (void)navigationController:(UINavigationController *)navigationController 
     willShowViewController:(UIViewController *)vc 
        animated:(BOOL)animated 
{ 
    UIBarButtonItem *myItem = /* initialize */; 

    navigationController.topViewController.navigationItem.backBarButtonItem = nil; 
    navigationController.topViewController.navigationItem.backBarButtonItem = myItem; 
} 
@end 

此外,還可以通過檢查閹-[NSObject isKindOfClass:]忽略自定義視圖控制器匹配想要的視圖控制器。

0

http://osmorphis.blogspot.com/2009/03/trapping-uinavigationbar-back-button.html

您可以在標準的後退按鈕更改的唯一事情是文本。默認情況下,這是控制器的標題。你可以用這樣的代碼更改:

[self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"New Title" style:UIBarButtonItemStyleBordered target:nil action:nil]; 

只需更換

initWithTitle:@"New Title" 

initWithTitle:@"Back" 
0

試着問問題之前,進行搜索。

似乎您可以將以下代碼添加到調用鑽取的控制器,即master-detail中的主控。

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil]; 
self.navigationItem.backBarButtonItem = backButton; 
[backButton release]; 

感謝iPhoneGuy這裏:iPhone Dev SDK