问题
I'm pushing a view like this.
[[self.navigationController pushViewController:myViewController animated:YES];
How Can I get class name of parent view controller from pushed view (child view)? Any Idea?
回答1:
This should do it:
NSUInteger numberOfViewControllersOnStack = [self.navigationController.viewControllers count];
UIViewController *parentViewController = self.navigationController.viewControllers[numberOfViewControllersOnStack - 2];
Class parentVCClass = [parentViewController class];
NSString *className = NSStringFromClass(parentVCClass);
回答2:
Get class of parent view controller:
id class = [self.navigationController.viewControllers[0] class];
and its name:
NSString *className = NSStringFromClass(class);
来源:https://stackoverflow.com/questions/15760175/get-class-name-of-parent-view-controller-in-iphone-navigation-push