添加rightBarButtonItem时BackBarButtonItem会发生变化

时间:2016-11-17 13:01:09

标签: ios objective-c iphone

我正在尝试添加一个backButtonItem但是当我稍后添加一个rightBarbuttonItem时它会被删除。

在父视图控制器中:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Name" style:UIBarButtonItemStylePlain target:nil action:nil];

self.navigationItem.backBarButtonItem = backButton;

这在我在子视图控制器中添加它之前可以正常工作:

UIBarButtonItem *buttonC = [[UIBarButtonItem alloc]initWithTitle:@"Word" style:UIBarButtonItemStylePlain target:self action:nil];

[self.navigationItem setRightBarButtonItem:buttonC];

这似乎删除了backButtonItem并将其替换为新的默认后退按钮。 如果我没有添加rightBarButtonItem,则backButtonItem工作正常。 有什么想法吗?

1 个答案:

答案 0 :(得分:0)

试试此代码

UIBarButtonItem *anotherButton1 = [[UIBarButtonItem alloc] initWithTitle:@"Button_1" style:UIBarButtonItemStylePlain target:self action:@selector(button_1:)];

UIBarButtonItem *anotherButton2 = [[UIBarButtonItem alloc] initWithTitle:@"Button_" style:UIBarButtonItemStylePlain target:self action:@selector(button_2:)];

self.navigationItem.rightBarButtonItems=@[anotherButton1,anotherButton2];