212,三种加载view的方法

来源:互联网 发布:apache配置https 编辑:程序博客网 时间:2024/05/16 06:51
  • 可以用isViewLoaded方法判断一个UIViewController的view是否已经被加载
AppDelegate.h:

#import <UIKit/UIKit.h>

@class OneViewController;

@class TwoViewController;

@class ThreeViewController;


@interface AppDelegate :UIResponder <UIApplicationDelegate>


@property (strong,nonatomic) UIWindow *window;


@property (nonatomic,strong)OneViewController *kOmeView;

@property (nonatomic,strong)TwoViewController *kTwoView;

@property (nonatomic,strong)ThreeViewController *kThreeView;


@end


AppDelegate.h:


    self.window =[[UIWindowalloc] initWithFrame:[UIScreenmainScreen].bounds];

    //1,使用纯代码创建view

    self.kOmeView = [[OneViewControlleralloc] init];

    self.window.rootViewController =self.kOmeView;

    

    //2,使用xib加载

    self.kTwoView = [[TwoViewControlleralloc] initWithNibName:@"TwoViewController"bundle:nil];

    self.window.rootViewController =self.kTwoView;

    

    //3,使用storyboard加载

    UIStoryboard *storyboard  = [UIStoryboardstoryboardWithName:@"ThreeViewController"bundle:nil];

    self.kThreeView = [storyboardinstantiateInitialViewController];

    self.window.rootViewController =self.kThreeView;

    [self.windowmakeKeyAndVisible];





0 0
原创粉丝点击