2012-12-14 183 views

回答

0

,如果您有任何UIView类(如的UIButton,UITable或任何其他子类),这是UIViewController.view的子视图(或任何subView.subView.subView的吧...)的

你可以检查是否有在superVew(S)链一个UIViewController,当你发现一个UIViewController

像这样停止:

UIViewController* controllerFound = nil; 
for (UIView* next = [self superview]; next; next = next.superview) { 
    UIResponder* nextResponder = [next nextResponder]; 
    if ([nextResponder isKindOfClass:[UIViewController class]]) { 
     controllerFound = (UIViewController*)nextResponder; 
    } 
} 
+0

我不知道这个,因为我没有使用这种方法。我需要找出页面视图控制器可以发布任何相关的东西。 –

22

我有同样的问题。看起来您更改页面后,当前控制器是列表中的最后一个。这对我有用,但我不知道它是否总是如此。

- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed 
{ 
    UIViewController *vc = [pageViewController.viewControllers lastObject]; 
} 
+0

谢谢,我会试试看。 –

+0

这是一个正确的答案。谢谢@CodeStage – Futur

+3

不起作用! – mnl

1

尝试在pageViewController.viewControllers

if let vc = pageViewController.viewControllers?[0] { 
     ... vc is current controller... 
    } 

如果要处理页面的变化得到的第一个视图控制器,做一个委托方法:

func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) { 
    if let vc = pageViewController.viewControllers?[0] { 
     ... vc is current controller... 
    } 
} 
相关问题