我需要在显示基于标签的应用程序之前显示视图,一旦用户点击按钮,视图就会消失。 有什么想法吗?
答案 0 :(得分: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];
}
答案 1 :(得分:0)
使用UIViewController。使用标签栏控制器将控制器显示为模态视图。之后关闭视图控制器以隐藏它