вот код, который демонстрирует процесс.Вы можете вставить этот код в делегат приложения для запуска.Обратите внимание, что это код спагетти, но я сделал это таким образом, чтобы вы могли увидеть все шаги в одном месте.Обычно вы помещаете части этого кода в его собственный контроллер представления и классы.
это в 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];
}