gpt4 book ai didi

iphone - 在显示 UITabBar 之前显示 View

转载 作者:可可西里 更新时间:2023-11-01 04:49:00 25 4
gpt4 key购买 nike

我需要在显示基于选项卡的应用程序之前显示 View ,一旦用户点击按钮, View 就会消失。有什么想法吗?

最佳答案

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

这是在 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];

}

关于iphone - 在显示 UITabBar 之前显示 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5845646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com