Controller和View物件的載入

weixin_34007291發表於2016-07-14

1.在xib中獲取UIView

  • 當xib的name跟關聯的view的類名一致時。
WNXUnLoginView *view = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([WNXUnLoginView class]) owner:nil options:nil] lastObject];
  • 通用的方式
WNXUnLoginView *view = [[[NSBundle mainBundle] loadNibNamed:@"WNXUnLoginView" owner:nil options:nil] lastObject];

2.在xib中獲取UITableViewCell物件(以下兩種方式一致)

WNXRmndCell *cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([WNXRmndCell class]) owner:nil options:nil] lastObject];
WNXRmndCell *cell =  [[[NSBundle mainBundle] loadNibNamed:@"WNXRmndCell" owner:nil options:nil] lastObject];

3.在xib中獲取UIViewController物件

GHViewController *vc = [[GHViewController alloc]initWithNibName:@"GHViewController" bundle:nil];

4.在storyBoard中獲取UIViewController物件

//@"registerLogin"是標識。
RegisterAndLoginController *registerAndLoginVC = [[UIStoryboard storyboardWithName:@"OtherSB" bundle:nil]instantiateViewControllerWithIdentifier:@"registerLogin"];  
//
LoginViewController *loginVC = [UIStoryBoard storyboardWithName:]; 

相關文章