Last active
December 20, 2015 01:48
-
-
Save gin0606/6051265 to your computer and use it in GitHub Desktop.
TabBar選択するとModalView開くやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
これの前に
self.tabBarController.delegate = self;
が必要です