我正在推这样的观点。
[[self.navigationController pushViewController:myViewController animated:YES];
如何从推送视图(子视图)获取父视图控制器的类名? Any Idea?
答案 0 :(得分:19)
这应该这样做:
NSUInteger numberOfViewControllersOnStack = [self.navigationController.viewControllers count];
UIViewController *parentViewController = self.navigationController.viewControllers[numberOfViewControllersOnStack - 2];
Class parentVCClass = [parentViewController class];
NSString *className = NSStringFromClass(parentVCClass);
答案 1 :(得分:4)
获取父视图控制器的类:
id class = [self.navigationController.viewControllers[0] class];
及其名称:
NSString *className = NSStringFromClass(class);