我已經做了以下方式
在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];
然後在頭添加符合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;
}
這是沒有做任何事情。 – 4thSpace 2010-05-17 04:23:39
你需要調整它到你的特定項目的代碼。您可能想要編輯您的問題以包含相關的代碼片段,即您在第一個視圖控制器中的位置並推送第二個視圖控制器。 – 2010-05-17 04:51:52
我已經更新了這個問題。謝謝。 – 4thSpace 2010-05-17 05:00:20