Skip to content

Instantly share code, notes, and snippets.

@gin0606
Last active December 20, 2015 01:48
Show Gist options
  • Save gin0606/6051265 to your computer and use it in GitHub Desktop.
Save gin0606/6051265 to your computer and use it in GitHub Desktop.
TabBar選択するとModalView開くやつ
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1, *viewController2;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil];
viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil];
} else {
viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPad" bundle:nil];
viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPad" bundle:nil];
}
CenterViewController *centerViewController = [[CenterViewController alloc] initWithNibName:@"CenterViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate = self;
self.tabBarController.viewControllers = @[viewController1, centerViewController, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
// 中略
#pragma mark UITabBarControllerDelegate method
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
if ([viewController isKindOfClass:[CenterViewController class]]) {
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor redColor];
[viewController presentViewController:vc animated:YES completion:nil];
return NO;
}
return YES;
}
@gin0606
Copy link
Author

gin0606 commented Jul 22, 2013

これの前に self.tabBarController.delegate = self; が必要です

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment