0

I have view controller which is inherited from UINavigationController. On viewDidLoad I want to set rightBarButtonItem. I do following.

UINavigationItem* navItem = self.navigationItem;
UIButton* btnOptionsView = [[UIButton alloc] init];
[btnOptionsView setImage:[UIImage imageNamed:@"options.png"]
                forState:UIControlStateNormal];
[btnOptionsView sizeToFit];
UIBarButtonItem* btnOptions = [[UIBarButtonItem alloc] initWithCustomView:btnOptionsView];
navItem.rightBarButtonItem = btnOptions;

but the button is invisible, in debug mode I have noticed that btnOptions.width is 0, and also I can't set the title for navItem, something like this

[navItem setTitle:@"title"]

does not change the title of UINavigationItem.

Hailei
  • 42,163
  • 6
  • 44
  • 69
taffarel
  • 4,015
  • 4
  • 33
  • 61

2 Answers2

0

try to change the title of the button

TompaLompa
  • 949
  • 6
  • 17
0

You should not subclassing UINavigationController. From apple documentation:

The UINavigationController class implements a specialized view controller that manages the navigation of hierarchical content. This class is not intended for subclassing. Instead, you use instances of it as-is in situations where you want your application’s user interface to reflect the hierarchical nature of your content.

Malek_Jundi
  • 6,140
  • 2
  • 27
  • 36