iphone - ModalView doesnt show up with tabbarcontroller -
i building app has login screen leads tabbar. followed example on how push modal view once launch app (as "sign in" page) , dismiss it.
example --> show / hide tab bar
from reason, it's not working - when launch app, see tabbar view 2 view controllers. no sign in page.
here code:
appdelegate:
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { // override point customization after application launch. self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; uiviewcontroller *viewcontroller1 = [[firsttab alloc] initwithnibname:@"firsttab" bundle:nsbundle.mainbundle]; uiviewcontroller *viewcontroller2 = [[secondtab alloc] initwithnibname:@"secondtab" bundle:nsbundle.mainbundle]; uinavigationcontroller *secondnavcontroller = [[uinavigationcontroller alloc]initwithrootviewcontroller:viewcontroller2]; self.tabbarcontroller = [[uitabbarcontroller alloc] init]; self.tabbarcontroller.viewcontrollers = [nsarray arraywithobjects:viewcontroller1, secondnavcontroller, nil]; self.window.rootviewcontroller = self.tabbarcontroller; [self.window makekeyandvisible]; return yes; }
my first tab (which understand modal view business needs happen)
.h
@interface firsttab : uiviewcontroller @end
.m
//updated code per comment below
- (void)viewdidload { [super viewdidload]; signin *loginview = [[signin alloc] initwithnibname:@"signin" bundle:nil]; uinavigationcontroller *controller = [[uinavigationcontroller alloc] initwithrootviewcontroller: loginview]; self.hidesbottombarwhenpushed = yes; [self presentmodalviewcontroller:controller animated:yes]; }
and of course, dismiss modal view in signin view controller, though never there mentioned.
what doing wrong here? help!!
you use :
[[self tabbarcontroller] presentmodalviewcontroller:controller animated:yes];
since first viewcontroller1
first tab, , self.navigationcontroller
might nil.
in custom view controller subclass called signin
implement initwithnibname:bundle:
instead if init
.
-(id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // init here } }
now when init/alloc call either :
signin *loginview = [[signin alloc] initwithnibname:@"signin" bundle:nil];
if interface in nib file, or :
signin *loginview = [[signin alloc] initwithnibname:nil bundle:nil];
if there no nib.
also why putting root view controller of navigation controller ? unless need go deeper in model data presentation, present directly :
// why ? //uinavigationcontroller *controller = [[uinavigationcontroller alloc] // initwithrootviewcontroller: loginview]; //self.hidesbottombarwhenpushed = yes; //[self presentmodalviewcontroller:controller animated:yes]; [self presentmodalviewcontroller:loginview animated:yes];
Comments
Post a Comment