ios - UIBarButton Title Only Shows Periodically -
i'm adding uitoolbar uiviewcontroller programmatically.
the problem have when view created buttons in toolbar "do" show not show title text.
if wait 10 - 20 seconds or longer titles show.
i tried calling setneedsdisplay , setneedslayout force ui yo update straight doesnt work.
am doing ridiculous? can't life of me figure out why title don't show immediately.
-(id)initwithframe:(cgrect)frame { self= [super init]; if (self) { uiview *view=[[uiview alloc]initwithframe:frame]; self.view=view; cellloader = [uinib nibwithnibname:cellclassname bundle:[nsbundle mainbundle]] ; self.tableview=[[uitableview alloc]initwithframe:cgrectmake(self.view.frame.origin.x, self.view.frame.origin.y+44, self.view.frame.size.width, self.view.frame.size.height-44) style:uitableviewstyleplain]; [self.tableview registerclass:[mycell class] forcellreuseidentifier:@"mycell"]; [self.view addsubview:self.tableview]; self.tableview.datasource=self; self.tableview.delegate=self; //[self.tableview setcontentinset:uiedgeinsetsmake(44, 0, 0, 0)]; navitem = [[uinavigationitem alloc] init]; uilabel* lbnavtitle = [[uilabel alloc] initwithframe:cgrectmake(-200,50,100,40)]; [lbnavtitle setbackgroundcolor:[uicolor clearcolor]]; lbnavtitle.textalignment = nstextalignmentleft; [lbnavtitle settextcolor:[uicolor whitecolor]]; lbnavtitle.text = nslocalizedstring(@"",@""); navitem.titleview = lbnavtitle; navibar = [[uinavigationbar alloc] init]; navibar.barstyle=uibarstyleblack; navibar.items = [nsarray arraywithobject:navitem]; navibar.frame = cgrectmake(0.0, 0, self.view.frame.size.width, 44.0); toolbar = [[uitoolbar alloc] initwithframe:cgrectmake(0, 0, 350, 44)]; toolbar.barstyle=uibarstyleblack; nsmutablearray *buttons = [[nsmutablearray alloc] initwithcapacity:7]; button1=[[uibarbuttonitem alloc] initwithtitle:@"button 1 text" style:uibarbuttonitemstylebordered target:self action:@selector(buttononepressed:)]; [buttons addobject: button1]; uibarbuttonitem *spacer1 = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemfixedspace target:nil action:nil]; [buttons addobject:spacer1]; button2=[[uibarbuttonitem alloc] initwithtitle:@"button 2 text" style:uibarbuttonitemstylebordered target:self action:@selector(button2pressed:)]; [buttons addobject:button2]; [toolbar setitems:buttons animated:no]; [self.view addsubview:toolbar]; [navibar setneedsdisplay]; [toolbar setneedsdisplay]; [self.view setneedsdisplay]; } return self; }
ok, if viewcontroller, don't want create view hierarchy in init method, instead, use viewdidload
method. (and don't have set self.view
yourself, default implementation in uiviewcontroller
you)
also, you're creating uinavigationbar
, uitoolbar
, setting same frames both when add toolbar subview... (i'll consider uinavigationbar
junk code too)
- (void)viewdidload { cellloader = [uinib nibwithnibname:cellclassname bundle:[nsbundle mainbundle]] ; self.tableview=[[uitableview alloc]initwithframe:cgrectmake(self.view.frame.origin.x, self.view.frame.origin.y+44, self.view.frame.size.width, self.view.frame.size.height-44) style:uitableviewstyleplain]; [self.tableview registerclass:[mycell class] forcellreuseidentifier:@"mycell"]; [self.view addsubview:self.tableview]; self.tableview.datasource=self; self.tableview.delegate=self; toolbar = [[uitoolbar alloc] initwithframe:cgrectmake(0, 0, 350, 44)]; toolbar.barstyle=uibarstyleblack; uibarbuttonitem *button1 = [[uibarbuttonitem alloc] initwithtitle:@"button 1 text" style:uibarbuttonitemstylebordered target:self action:@selector(buttononepressed:)]; uibarbuttonitem *spacer1 = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemfixedspace target:nil action:nil]; uibarbuttonitem *button2 = [[uibarbuttonitem alloc] initwithtitle:@"button 2 text" style:uibarbuttonitemstylebordered target:self action:@selector(button2pressed:)]; // using objective-c litterals shorter code using nsmutablearray ! [toolbar setitems:@[button1, spacer1, button2] animated:no]; [self.view addsubview:toolbar]; } }
normally, that's need (no call setneedsdisplay
, these done automatically when adding subviews)
Comments
Post a Comment