我的 TabBarView 中有一个导航栏。我想要一个 rightBarButtonItem 和我的导航栏上的标题。为什么会这样?我的代码在 viewDidLoad 方法中。为什么我的标题显示为左键项?然后当我点击它时,它就像在移动一个视图,然后我的右栏按钮项目消失了,标题是正确的。
UINavigationBar *myNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320,40)];
myNavBar.barStyle = UIBarStyleBlackOpaque;
[self.view addSubview:myNavBar];
//Creates the title.
UINavigationItem *title = [[UINavigationItem alloc] initWithTitle:@"My Title"];
[myNavBar pushNavigationItem:title animated:NO];
//Creates the button.
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self
action:@selector(showMail:)];
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:nil];
navItem.rightBarButtonItem = button;
// add the UINavigationItem to the navigation bar
[myNavBar pushNavigationItem:navItem animated:NO];