objective c - Add button to navigationbar programmatically -


Hello my navigation bar button in the right direction will be set programmatically, so I button Dbaooga I do some actions I've created the navigation bar, programmatically;

  navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake (0,0,320,44)];  

Similarly, I need to add buttons to the right of this navigation bar for I used,

1. & nbsp;

  UIView * container = [[UIView alloc] init]; // Create a button and container UIButton * Add button [[UIButton alloc] initWithFrame: CGRectMake (0, 0, 130, 44.01)]; [Container adsview: button]; [Button release]; // Add another button button = [[UIButton alloc] initWithFrame: CGRectMake (160, 0, 50, 44.01)]; [Container adsview: button]; [Button release]; // Now button items UIBarButtonItem * items = [[UIBarButtonItem alloc] initWithCustomView: Container]; // Set the right button items of the Navy Bar manually. NavigationItem.rightBarButtonItem = item; [Item release];  

2. & nbsp;

  UIImage * im; Im = [UIImage imageNamed: @ "back.png"]; [Button set image: im forState: UIControlStateNormal]; [Im release]; Backbutton = [[UIBarButtonItem alloc] initWithCustomView: button]; [BackButton setImageInsets: UIEdgeInsetsMake (0, -10,5, 5)]; [Self. Navigation Itam Setwritebutboottime: Backbutton];  

3. & nbsp;

  UIBarButtonItem * refreshItem = [[UIBarButtonItem alloc] initWithTitle: @ "button" style: UIBarButtonItemStylePlain goal: self action: @selector (fresh Logsakshn :)]; Self.navigationItem.rightBarButtonItem = refreshItem; [Refresh item release];  

I tried all these methods, but no one is displaying buttons on the right hand.

UIViewController in the derived class, I'm using inside the viewDidLoad :

  UIBarButtonItem * flipButton = [[UIBarButtonItem alloc] initWithTitle: @ "flip" style: UIBarButtonItemStyleBordered goal: self action: @selector (flip view :)]; Self.navigationItem.rightBarButtonItem = FlipButton; [Flip button release];  

It adds a button in the right hand with title Flip, which calls the method:

- (IBAction) Flip view

This is very much like you # 3, but it is working within my code.


Comments