ios - UIViewController 未加载

标签 ios swift uiviewcontroller

所以我有一个登录函数,用于解析和验证登录。然后,当它返回时,我使用以下代码呈现不同的 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/

相关文章:

objective-c - numberOfSectionsInTableView 之后 UITableViewController 崩溃

ios - 通过 UINavigationControllerDelegate 接收 ViewDidUnload 消息

ios - Swift 中两位小数之间的随机数

ios - 编辑事件不起作用

ios - 自动布局:保持 View 的centerX与另一个 View 相同,但不超越其 super View

xcode - Swift 中通过可选绑定(bind)进行安全(边界检查)数组查找?

swift - 如何在 Xcode 中使用 Apple 的 swift-format?

ios - 带有 CGPath 的 UIView 和另一个包含第一个 UIView 的 UIView。如何使第一个 View 适合第二个 View ?

ios - 如何有效地将CoreImage过滤器应用于视频文件?

swift - 如何在导航栏的普通标题和大标题上使用不同的样式?