在childViewController中显示inputAccessoryView

时间:2015-06-07 11:18:32

标签: ios swift

我有一个父视图控制器,它充当UIPageViewController和另一个UIViewController(称为commentsViewController)的容器。我想在inputAccessoryView内显示commentsViewController,但它似乎不起作用。我已将commentsViewController添加到父级,如下所示:

commentsViewController = storyboard!.instantiateViewControllerWithIdentifier("CommentsViewController")! as! CommentsViewController
self.addChildViewController(commentsViewController)
self.view.addSubview(commentsViewController.view)
//...I have set some autolayout constraints here
commentsViewController.didMoveToParentViewController(self)

然后在CommentsViewController内,我有以下内容:

@IBOutlet var customView: UIView!
override var inputAccessoryView: UIView {
    return customView
}

override func canBecomeFirstResponder() -> Bool {
    return true
}

override func viewDidLoad() {
    super.viewDidLoad()
    self.becomeFirstResponder()
}

不幸的是,这不起作用,并且没有显示inputAccessoryView ......任何人都可以看到我缺少的东西吗?

谢谢。

1 个答案:

答案 0 :(得分:1)

事实证明,因为我在制作视图动画,becomeFirstResponder()会自动返回false。动画完成后效果很好。