获取最顶层的视图控制器 iOS
1、获取当前所展示的控制器:
//需要获取到显示在最上面的viewController - (UIViewController *)theTopviewControler{ //获取根控制器 UIViewController *rootVC = [[UIApplication sharedApplication].delegate window].rootViewController; UIViewController *parent = rootVC; //遍历 如果是presentViewController while ((parent = rootVC.presentedViewController) != nil ) { rootVC = parent; } while ([rootVC isKindOfClass:[UINavigationController class]]) { rootVC = [(UINavigationController *)rootVC topViewController]; } return rootVC; }
2.找到当前视图的父视图控制器
- (UIViewController *)viewController { for(UIView* next = [self superview]; next; next = next.superview) { UIResponder*nextResponder = [next nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) { return(UIViewController*)nextResponder; } } return nil; }
在北京的灯中,有一盏是我家的。这个梦何时可以实现?哪怕微微亮。北京就像魔鬼训练营,有能力的留,没能力的走……