无法以编程方式将UIBarButton添加到UINavigationBar(UITabbarController)

时间:2015-08-01 05:27:09

标签: ios objective-c uiviewcontroller storyboard uitabbarcontroller

我有一个UITabbarController并连接到5个UIViewController,我已经将UIBarButton添加到ViewController1中的UINavigationbar。

但是当我运行该应用程序时,我无法在导航栏中看到UIBarButton,我只能看到一个普通的导航栏。

这是更新UINavigationBar的代码。

UIImage *myImage = [UIImage imageNamed:@"filter.png"];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton setImage:myImage forState:UIControlStateNormal];
myButton.showsTouchWhenHighlighted = YES;
myButton.frame = CGRectMake(0.0, 0.0,25,25);
[myButton addTarget:self action:@selector(refreshSection) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:myButton];
self.navigationItem.leftBarButtonItem = rightButton;

这没有UITabbarController,但是当我将UITabbarController添加到我的故事板时,它不起作用请帮助我..

0 个答案:

没有答案