你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> ios 控制器 modal 學習

ios 控制器 modal 學習

編輯:IOS開發綜合

代碼創建:

1、appdelegate 把contoller放到跟controller下

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.rootViewController = [[MJOneViewController alloc] init];
    
    [self.window makeKeyAndVisible];
    return YES;
}
2、oneViewController跳轉的action

拿到要跳轉的控制器的,然後通過當前的controller 來 調用 presentViewController

- (IBAction)jump {
    // 展示MJTwoViewController
    MJTwoViewController *two = [[MJTwoViewController alloc] init];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:two];
    
    [self presentViewController:nav animated:YES completion:^{
        NSLog(@"展示MJTwoViewController完畢.......");
    }];
}
3、twoController 返回之前的controller

調用 dismissViewController方法

- (IBAction)cancel {
//    NSLog(@"%@", self.view.window.rootViewController);
//    NSLog(@"%@", self.view.window.subviews);
    [self dismissViewControllerAnimated:YES completion:^{
        NSLog(@"關閉MJTwoViewController....");
    }];
//    [self.navigationController dismissViewControllerAnimated:YES completion:^{
//        NSLog(@"關閉MJTwoViewController....");
//    }];
}


在storyBoard創建modal控制器也很方便,直接ctrl 右擊 選在moadal模式




  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved