在显示UITabBar之前显示视图

irc*_*rco 5 iphone uitabbarcontroller uiview ios

我需要在显示基于选项卡的应用程序之前显示视图,一旦用户点击按钮,视图就会消失.有任何想法吗?

Jas*_*gun 2

这是演示该过程的一些代码。您可以将此代码粘贴到应用程序委托中来运行。请注意,这是意大利面条式代码,但我这样做是为了让您可以在一个地方看到所有步骤。通常,您会将部分代码放入其自己的视图控制器和类中。

这是在 appdelegate 中。请注意,这还没有完全测试泄漏和其他内容。它只是一个示例。

@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];

}
Run Code Online (Sandbox Code Playgroud)