未显示自定义UIViewController的视图

时间:2015-05-07 21:00:09

标签: ios swift uiviewcontroller xib

所以我有这个视图控制器,它有一个xib文件,我检查了文件的所有者以及视图插座,同时连接了类和xib文件。但是如果我想推送这个视图控制器,即使调用了所有方法,它也会显示一个空的:viewDidLoadviewWillAppear

self.navigationController?.presentViewController(
  TourViewController(nibName: "TourViewController", bundle: nil), animated: false, completion: nil
)

这是视图控制器:

class TourViewController: TLViewController {

  override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    println("nib init")
  }

  required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
  }

  override func viewDidLoad() {
    super.viewDidLoad()
    println("didLoad")

  }

  override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    println("appear")
  }

}

我更改了颜色背景,并且还为XIB添加了标签

1 个答案:

答案 0 :(得分:0)

嗯,问题发生在我的CUSTOM TLViewController

override func loadView() {
    super.loadView()

    screen = UIScreen.mainScreen().bounds
    visibleFrame = CGRectMake(
      0.0,
      20.0 + 44.0,
      screen.size.width,
      screen.size.height - (20.0 + 44.0)
    )

    view = UIView(frame: screen)
    view.backgroundColor = UIColor.whiteColor()

    self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()
    self.navigationController?.navigationBar.tintColor = UIColor.backgroundMenu()
    self.navigationController?.navigationBar.titleTextAttributes =
      [NSForegroundColorAttributeName: UIColor.backgroundMenu()]
    // Back Button
    self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "",
      style: .Plain, target: nil, action: nil)

    var menuBtn = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
    menuBtn.setImage(UIImage(named: "menu-ico"), forState: UIControlState.Normal)
    menuBtn.addTarget(self, action: Selector("menu"), forControlEvents:  UIControlEvents.TouchUpInside)
    leftMenuButtonItem = UIBarButtonItem(customView: menuBtn)
  }

所以我改变了

class TourViewController: TLViewController 

class TourViewController: UIViewController