开发者

How to change the text on UINavigationBar backButton item?

I know the label on b开发者_开发知识库ack button item is always the last view clicked, but how should I go if I want to have "back" text on it?


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


This issue bugs me as well. My hack is to change the title of the view controller in -viewWillAppear: and -viewWillDisappear:, where the latter changes the title to what will appear on the "back" button and the former changes it back to what I want the title of that screen to be. For example,

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    myViewController.navigationItem.title = @"My Title";
}

-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    myViewController.navigationItem.title = @"Back";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜