美文网首页
iOS-各种加载

iOS-各种加载

作者: CDLOG | 来源:发表于2018-07-23 16:32 被阅读35次

1,从Xib当中加载控制器.

initWithNibName:如果指定了名称,那么它就会去加载指定名称的Xib.
MyViewController *vc = [[MyViewController alloc] initWithNibName:@"VC" bundle:nil];

如果没有指定名称.指定为nil,那么它就会去先加载跟它相同名称的Xib.

2,加载指定的控制器(UIStoryboard)

0.加载指定的StoryBoard.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

1.加载箭头所指向的控制器.
UIViewController *vc = [storyBoard instantiateInitialViewController];

2.加载指定标识的控制器.
UIViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"VCStoryBoardID"];

3,加载xib文件

NSArray *objs = [[NSBundle mainBundle]loadNibNamed:@"XibView" owner:nil options:nil];
UIView *xibView = objs[0];

4,加载plist文件

 NSString *path = [[NSBundle mainBundle] pathForResource:@"imageData.plist" ofType:nil];
        // 从plist文件解析数组
_imageData = [NSArray arrayWithContentsOfFile:path];

5,依赖注入

//在自己的控制器的init方法要可以传入model,把该init方法放在.h文件方便别人调用
-(instancetype)initWithOrderModel:(Model *)model{
    if (self = [super init]) {
        self.model = model;
    }
    return self;
}

相关文章

网友评论

      本文标题:iOS-各种加载

      本文链接:https://www.haomeiwen.com/subject/rrjjmftx.html