IOS:UIViewController
lastmod 2014-03-25created 2014-02-0715 edits
View Life cycle
The meaning of each call to the UIViewController lifecycle methods is as follows.
- viewDidLoad: called when the view has loaded.
- viewWillAppear: called when the view is ready to appear.
- viewDidAppear: called when the view is fully visible.
- viewWillDisappear: called when the view is ready to disappear.
- viewDidDisappear: called when the view has fully disappeared.
Change View
- First, add an
IBActioninterface.```objc - (IBAction) moveSecondView: (id) sender;</li> <li markdown="1"> Build the screen, create a button, and connect it to moveSecondView. </li> <li markdown="1"> Import the header file of the second view. </li> <li markdown="1"> Implement the action declared in the header file.```objc - (IBAction) moveSecondView: (id) sender { SecondView *secondview = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil]; // SecondView의 초기화 [self.view addSubview:secondview.view]; // 현재 뷰에서 SecondView를 추가하겠다는 의미 }
Root ViewController
To set the first ViewController, add the following in AppDelegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// This code !!!
MainViewController * view = [[MainViewController alloc] init];
self.window.rootViewController = view;
return YES;
}
Top Index Modal ViewController
A method implementation that presents a view as the topmost modal view is shown below.
#pragma mark - Modal VC
- (void)presentModalVC:(UIViewController*)controller animated:(BOOL)animated
{
// 가장 최상위 모달로 이동.
UIViewController* visibleRootViewController = self.tabBarController;
while (visibleRootViewController.presentedViewController != nil)
{
visibleRootViewController = visibleRootViewController.presentedViewController;
}
// 최상위 모달 위에 모달을 띄운다.
[visibleRootViewController presentModalViewController:controller animated:animated];
}
- (void)dismissModalVCAnimated:(BOOL)animated
{
[self.tabBarController dismissModalViewControllerAnimated:animated];
}
Deprecated presentModalViewController
As a follow up to the last post, I also had presentModalViewController all over my app and it too has been deprecated. I quickly found the answer:
can be replaced by:
Hide Status Bar
To hide the StatusBar in iOS7, add the code below.
// Insert viewDidLoad
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
// Override prefersStatusBarHidden
- (BOOL)prefersStatusBarHidden
{
return YES;
}
To show the StatusBar, change the return value of the prefersStatusBarHidden function to NO.