Created
January 5, 2012 13:34
-
-
Save laiso/1565279 to your computer and use it in GitHub Desktop.
呼び出しが pushViewController でも presentModalViewController でも対応できるViewController 用のスニペット
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
@interface ChildController () | |
@property(nonatomic, retain) UINavigationController* navigationController; | |
@end | |
@implementation ChildController | |
@synthesize navigationController; | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
/** | |
* 呼び出しが pushViewController でも presentModalViewController でも対応できるViewController 用のスニペット | |
*/ | |
if( !self.navigationController && ![self.parentViewController isKindOfClass:[UINavigationController class]] ){ | |
/** 親元不明のModalViewController はNavigationBar と閉じるボタンをつけてやる */ | |
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self]; | |
UIBarButtonItem* backButton = [[UIBarButtonItem alloc] init]; | |
backButton.style = UIBarButtonItemStylePlain; | |
backButton.title = @"閉じる"; | |
backButton.target = self; | |
backButton.action = @selector(dismissModalViewControllerAnimated:); | |
self.navigationItem.rightBarButtonItem = backButton; | |
self.navigationController.view = self.view; | |
[self.view addSubview:self.navigationController.navigationBar]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment