我已经通过以下方式完成了
在 viewDidLoad 方法中,我有以下代码:
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 41)];
navBar.delegate = self;
UINavigationItem *backItem = [[UINavigationItem alloc] initWithTitle:@"Back"];
[navBar pushNavigationItem:backItem animated:NO];
[backItem release];
UINavigationItem *topItem = [[UINavigationItem alloc] initWithTitle:@"Your Title"];
[navBar pushNavigationItem:topItem animated:NO];
topItem.leftBarButtonItem = nil;
[topItem release];
[self.view addSubview:navBar];
[navBar release];
然后在 header 中添加对 UINavigationBarDelegate 协议的一致性,并以这种方式实现委托方法:
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item
{
//if you want to dismiss the controller presented, you can do that here or the method btnBackClicked
return NO;
}