在swift中从单独的nib文件加载UIViewController? [英] Load UIViewController from the separate nib file in swift?

查看:421
本文介绍了在swift中从单独的nib文件加载UIViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把一个ViewController带到了单独的nib文件中。我的初始根视图控制器在storyBoard中设置。现在的问题是当我推送到这个控制器时,没有调用View hireachy方法(ViewDidLoad,ViewWillApper等)..

I had take one ViewController with separate nib file. and my initial root viewcontroller is set in the storyBoard. Now the problem is that when I push to this controller the View hireachy methods are not being called (ViewDidLoad , ViewWillApper , etc)..

代码(视图已加载但方法未调用)

Code (View is loaded but methods are not calling)

var viewController = UIViewController(nibName: "OfferDetailViewController", bundle: nil) as OfferDetailViewController
 self.navigationController?.pushViewController(viewController, animated: true);

如果我使用故事板工作正常,同样的事情。

The same thing if i do with the storyboard its working fine.

    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    var viewController = mainStoryboard.instantiateViewControllerWithIdentifier("offer") as OfferDetailViewController     
   self.navigationController?.pushViewController(viewController, animated: true);

问题:使用storyboard查看层次结构方法正在调用但不是单独的nib文件?

Problem : With storyboard View hierarchy methods are calling but not with the separate nib file?

推荐答案

var viewController = OfferDetailViewController(nibName: "OfferDetailViewController", bundle: nil)

这篇关于在swift中从单独的nib文件加载UIViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆