ios - Adding UIButtonBarItem programmatically to UINavigationBar -


i'am trying add uibuttonbaritem programmatically uinavigationbar. have class topbar, import on of viewcontrollers, , invoke by: [self.view addsubview:[topbar inserttopbar]];

#import "topbar.h"  @implementation topbar  +(uinavigationbar*)inserttopbar {     uinavigationbar *navbar = [ [uinavigationbar alloc] initwithframe:cgrectmake(0, 0, 320, 44)];      uinavigationitem *navtitle = [uinavigationitem alloc];     navtitle.title = @"myapp";      uinavigationitem *navadd = [uinavigationitem alloc];     navadd.leftbarbuttonitem = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem: uibarbuttonsystemitemadd target:self action:@selector(addfood)];      [navbar setitems:@[navadd, navtitle] animated:false];     return navbar; }  @end 

but when try set items using navbar setitems:@[navadd, navtitle] ads "back"-button enter image description here

if leave out navtitleso reads navbar setitems:@[navadd], "+"-sign appears. seems "navtitle" pushes first item. enter image description here

try out following method, did tweeks , working fine me now! :)

enter image description here

-(uinavigationbar*)inserttopbar { uinavigationbar *navbar = [ [uinavigationbar alloc] initwithframe:cgrectmake(0, 0, 320, 44)]; uinavigationitem *navadd = [uinavigationitem alloc]; navadd.leftbarbuttonitem = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem: uibarbuttonsystemitemadd target:self action:@selector(addfood)]; [navbar pushnavigationitem:navadd animated:yes]; navbar.topitem.title = @"myapp"; return navbar; } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -