所以我有一个登录函数,用于解析和验证登录。然后,当它返回时,我使用以下代码呈现不同的 View 。
var storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil);
var vc: UIViewController = storyBoard.instantiateViewControllerWithIdentifier("ProfileView") as UIViewController
println("got here");
self.presentViewController(vc, animated: true, completion: nil);
println("got here too");
gothere打印到控制台gothere也没有,ProfileView的 View 加载函数永远不会被调用。编译过程中日志中没有错误,也没有警告。应用程序不会崩溃我可以继续尝试登录,但它永远不会加载下一个 View 或打印第二条消息。
代码确实有效,但后来我稍微改变了 ProfileView,它就停止了。我已经恢复了 View ,但它仍然破损,我已经清理并重建了。有什么我应该特别寻找的吗?
根据要求,这里是 ProfileView 的顶行。
class ProfileView: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var profileImage: UIImageView!
var profilePic: PFObject!
var imageArray: [PFObject]!
当我使用 init 方法实例化这些对象时,init 方法将运行,我可以在它上断点,但 View 不会加载,因为我从未在 viewDidLoad 的第一行上断点。
最佳答案
看起来 Storyboard Identifier 没有在 Interface Builder 中设置为 ProfileView
。另外,如果您想设置配置文件 View Controller 特定属性,则不应强制转换为 UIViewController
,而应使用配置文件 View Controller 的类
拥有一个通过辅助方法加载 View Controller 的 UIStoryboard
扩展也可能会有所帮助,例如
extension UIStoryboard {
class func loadProfileViewController() -> ProfileViewController {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
return storyboard.instantiateViewControllerWithIdentifier("ProfileView") as! ProfileViewController
}
}
这样你就可以编写let profileVC = UIStoryboard.loadProfileViewController()
关于ios - UIViewController 未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30834374/