xib 和 storyboard

2017-03-16  本文已影响0人  哎呦哎呦小葵花

xib和storyboard的对比


xib的加载

// 方法1
NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"xib文件名" owner:nil options:nil]

// 方法2
UINib *nib = [UINib nibWithNibName:@"xib文件名" bundle:nil];
NSArray *views = [nib instantiateWithOwner:nil options:nil];

// 然后取出数组的lastObject

使用xib自定义的步骤

73fed72c-d1a4-41f6-bf5a-e3f214d2fcd0.png f333d723-937d-481a-b856-4074d878eda8.png 1fe47d50-2e9d-4579-b7d0-97deb6ebd7cc.png 6e30c180-4ec7-47b5-9a94-309546d7507d.png 91a8be0f-e213-4ae5-8396-7c5bdb167405.png

xib加载控制器

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

// 加载xib
FKViewController *rootView = [[FKViewController alloc] initWithNibName:@"FKViewController" bundle:nil];

self.window.rootViewController = rootView;
[self.window makeKeyAndVisible];
481131b6-c409-4d82-af15-6b378d27ca6b.png 2e80bb14-b953-432d-a47f-06ab9e69458b.png

特殊情况

  FKViewController *fkView = [[FKViewController alloc] initWithNibName:nil bundle:nil];
  // 或者
  FKViewController *fkView = [[FKViewController alloc] init];

b43f5c4a-6b48-4ba2-83d8-0bbb205c760e.png
上一篇 下一篇

猜你喜欢

热点阅读