Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show View before displaying thee UITabBar

I need to display a view before I display a tab based app and once the user taps a button the view goes away. Any ideas?

like image 570
irco Avatar asked Nov 05 '22 22:11

irco


1 Answers

here is some code that demonstrates the process. You can paste this code into the app delegate to run. Note, that this is spaghetti code, but I did it this way so you can see all the steps in one place. Normally, you will put parts of this code into its own view controller and classes.

this is in the appdelegate.. note that this is not completely tested for leaks and stuff.. its meant for an example.

@synthesize  tabViewController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


    UIWindow *w = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];;
    self.window = w; //property defined in the .h file
    [w release];


    //create the tab bar controller
    UITabBarController *tbc = [[UITabBarController alloc]init];
    self.tabViewController = tbc;
    [w addSubview:tbc.view];

    //create the two tabs
    NSMutableArray *a = [[NSMutableArray alloc]init];

    //create the first viewcontroller 
    UIViewController *vca = [[UIViewController alloc]init];
    vca.view.backgroundColor = [UIColor redColor];
    vca.title = @"View A";
    [a addObject:vca];
    [vca release];

    //and the second
    UIViewController *vcb = [[UIViewController alloc]init];
    vcb.view.backgroundColor = [UIColor blueColor];
    vcb.title = @"View B";
    [a addObject:vcb];
    [vcb release];

    //assign the viewcontrollers to the tabcontroller
    tbc.viewControllers=a;

    //release the array now that its retained by the tabcontroller
    [a release];
    [tbc release];  //tabbarcontroller is retained by our property


    UIViewController *vcc = [[UIViewController alloc]init];  //this is the popup view
    vcc.view.backgroundColor = [UIColor whiteColor];
    UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    b.titleLabel.text = @"Click here";
    [b addTarget:self action:@selector(buttonDismiss:) forControlEvents:UIControlEventTouchUpInside]; //hook into the buttons event
    b.frame = CGRectMake(10, 10, 300, 40);  
    [vcc.view addSubview:b]; //add it to the popup view



    [tbc presentModalViewController:vcc animated:YES];

    [self.window makeKeyAndVisible];
    return YES;
}

-(void) buttonDismiss:(UIButton *)sender
{
    [self.tabViewController dismissModalViewControllerAnimated:YES];

}
like image 158
Jason Cragun Avatar answered Nov 11 '22 06:11

Jason Cragun