I'm trying to create a detail view for documents. The top part of the detail view is a card-style layout of 90 pixels high, and below is a view pager switching between two controllers: InfoViewController (show some meta info) and DocumentViewController (show pdf).
I've laid out the top level controller (DetailViewController) in a xib file with two UIViews: viewForCard and viewForPager. However, the outlets defined in InfoViewController and DocumentViewController are not yet initialized when their viewDidLoad method is called. Anyone have any idea why?
The main code in DetailViewController (constraints for the container views viewForCard and viewForPager have been set up in the xib file:
@IBOutlet weak var viewForCard: UIView!
@IBOutlet weak var viewForPager: UIView!
var pageViewController:UIPageViewController = UIPageViewController()
var infoVC:InfoViewController = InfoViewController()
var documentVC:DocumentViewController = DocumentViewController()
override func viewDidLoad() {
super.viewDidLoad()
pageViewController.delegate = self
pageViewController.dataSource = self
addChildViewController(pageViewController)
pageViewController.setViewControllers([infoVC], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
initLayout()
}
func initLayout(){
var cardView:UIView = Card(document: document).contentView
cardView.setTranslatesAutoresizingMaskIntoConstraints(false)
var pagerView = pageViewController.view
pagerView.setTranslatesAutoresizingMaskIntoConstraints(false)
viewForCard.addSubview(cardView)
viewForPager.addSubview(pagerView)
let bindings = ["card": cardView, "pager": pagerView]
viewForCard.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0.0-[card]-0.0-|", options: nil, metrics: nil, views: bindings))
viewForCard.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("|-0.0-[card]-0.0-|", options: nil, metrics: nil, views: bindings))
viewForPager.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0.0-[pager]-0.0-|", options: nil, metrics: nil, views: bindings))
viewForPager.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("|-0.0-[pager]-0.0-|", options: nil, metrics: nil, views: bindings))
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?{
if viewController == documentVC{
return infoVC
}else{
return nil
}
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController?{
if viewController == infoVC{
return documentVC
}else{
return nil
}
}