ios - Add a new viewcontroller to a tab controller -
i have tab bar controller created mainwindow.xib. have 4 view controllers in it. want add together 5th item programatically (because dont know class have utilize until compile time)
this code:
uiviewcontroller * login = [[loginuserviewcontroller alloc] initwithnibname:@"loginuserviewcontroller" bundle:nil]; nsmutablearray * viewcontrollersarray = [nsmutablearray arraywitharray:self.tabbarcontroller.viewcontrollers]; [viewcontrollersarray addobject:login]; [self.tabbarcontroller setviewcontrollers:viewcontrollersarray animated:yes];
but
[loginuserviewcontroller viewcontrollers]: unrecognized selector sent instance 0x95791b0'
when reach code
uinavigationcontroller *navcontroller = [tabbarcontroller.viewcontrollers lastobject]; loginviewcontroller * log = [navcontroller.viewcontrollers objectatindex:0];
where going wrong? ideas?
thanks lot
try this....
- (void) setuptabbar { firstviewcontroller *firstviewcontroller = [[firstviewcontroller alloc]init]; firstviewcontroller.title = @"first view"; firstviewcontroller.tabbaritem = [[uitabbaritem alloc]initwithtabbarsystemitem:uitabbarsystemitemsearch tag:0]; uinavigationcontroller *firstnavcontroller = [[uinavigationcontroller alloc]initwithrootviewcontroller:firstviewcontroller]; secondviewcontroller *secondviewcontroller = [[secondviewcontroller alloc]init]; secondviewcontroller.title = @"second view"; secondviewcontroller.tabbaritem = [[uitabbaritem alloc]initwithtabbarsystemitem:uitabbarsystemitemfavorites tag:1]; uinavigationcontroller *secondnavcontroller = [[uinavigationcontroller alloc]initwithrootviewcontroller:secondviewcontroller]; thirdviewcontroller *thirdviewcontroller = [[thirdviewcontroller alloc]init]; thirdviewcontroller.title = @"third view"; thirdviewcontroller.tabbaritem = [[uitabbaritem alloc]initwithtabbarsystemitem:uitabbarsystemitemrecents tag:2]; uinavigationcontroller *thirdnavcontroller = [[uinavigationcontroller alloc]initwithrootviewcontroller:thirdviewcontroller]; forthviewcontroller *forthviewcontroller = [[forthviewcontroller alloc]init]; forthviewcontroller.title = @"forth view"; forthviewcontroller.tabbaritem = [[uitabbaritem alloc]initwithtabbarsystemitem:uitabbarsystemitemhistory tag:2]; uinavigationcontroller *forthnavcontroller = [[uinavigationcontroller alloc]initwithrootviewcontroller:forthviewcontroller]; tabbarcontroller = [[uitabbarcontroller alloc] initwithnibname:nil bundle:nil]; tabbarcontroller.viewcontrollers = [[nsarray alloc] initwithobjects:firstnavcontroller, secondnavcontroller, thirdnavcontroller, forthnavcontroller, nil]; tabbarcontroller.delegate = self; [self sizeviewtoavailablewindow:[tabbarcontroller view]]; [firstnavcontroller release]; [firstviewcontroller release]; [secondnavcontroller release]; [secondviewcontroller release]; [thirdnavcontroller release]; [thirdviewcontroller release]; [forthnavcontroller release]; [forthviewcontroller release]; }
ios cocoa-touch uiviewcontroller uinavigationcontroller uitabbarcontroller
No comments:
Post a Comment