我有一个带viewController
的containerView
。从pageView滑动视图后,我想在viewController中调用一个函数,我已经尝试了下面的代码,但它正在调用pageView
,请问我的问题在哪里?
class PlaceMenuDetailsViewController: UIViewController, PageViewSliderDelegate {
override func viewDidLoad() {
super.viewDidLoad()
detailsButton.pageDelegation = self
}
func buttonMaskColor(){
println("delegate work")
}
}
class DetailPageViewController: UIPageViewController, UIPageViewControllerDelegate, UIPageViewControllerDataSource {
weak var pageDelegation:PageViewSliderDelegate?
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
pageDelegation?.buttonMaskColor()
var page = (viewController as! PageDelegate).pageNumber + 1
return viewControllerForPage(page)
}
最佳答案
您应该在主视图中的prepareForSegue函数中为pageDelegation分配self,然后为嵌入的segue指定标识符,如下所示:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "embedSegueIdentifier" {
let distinationVC = segue.destinationViewController as? DetailPageViewController
distinationVC?.pageDelegation = self
}
}