I have following code to create UINavigationBar and set the navigation item with a back button at the right side.

 UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 60)];
navBar.delegate = self;
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:self action:@selector(backButtonTapped)];

UINavigationItem *backItem = [[UINavigationItem alloc] init];
[backItem setTitle:@"What's New"];
[backItem setLeftBarButtonItem:back];
backItem.leftBarButtonItem.enabled = YES;
[navBar pushNavigationItem:backItem animated:NO];

[self.view addSubview:navBar];

This worked perfectly until i update my xCode 5 to iOS 7.1 update recently.

But now when the UIView presented the navigation button is not visible. But when i touch the location of the button (where it used to be before the update), it shows me the button and click even is firing.

My question is how to set the button visible at the moment view is present to user ?

Thank you.

有帮助吗?

解决方案 2

Thanks to all,

finally what happen is as follows.

The above behaviour is not what i assume it is. When a new view is loaded the button is disappear by default and only if i move my finger here & there on the location button used to be it appears. Further when i keep the view still, after it loaded, about 15 seconds, button appears.

So i suspect this is with "viewDidLoad" method. (Code related to this UINavigationBar is in viewDidLoad method.

When I move above code to "viewDidAppear" method it start to work again.

其他提示

Try to initialize your UIBarButtonItem with initWithCustomView. Also, try to set buttonType of the UIButton to UIButtonTypeSystem.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top