我想在页面视图控制器中获取当前的视图控制器。如何做到这一点。它是否有一些代表要打电话或什么。
问问题
7983 次
3 回答
25
我只是有同样的问题。在您更改页面后,当前控制器看起来是列表中的最后一个。这对我有用,但我不知道它是否总是正确的。
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
UIViewController *vc = [pageViewController.viewControllers lastObject];
}
于 2012-12-16T22:56:47.797 回答
2
尝试在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...
}
}
于 2017-10-06T17:38:24.897 回答
0
if you are in any UIView class (as UIButton, UITable or any other subclass) that is a subView of the UIViewController.view (or of any subView.subView.subView... of it)
you can check if there's a UIViewController in the superVew(s) chain, and stop when you find a UIViewController
something like this:
UIViewController* controllerFound = nil;
for (UIView* next = [self superview]; next; next = next.superview) {
UIResponder* nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
controllerFound = (UIViewController*)nextResponder;
}
}
于 2012-12-14T11:36:38.230 回答