在iPhone导航推获取父视图控制器的类名(Get class name of Parent Vie

2019-08-19 00:20发布

我推着这样的观点。

[[self.navigationController pushViewController:myViewController animated:YES];

我怎样才能从推视图(子视图)的父视图控制器的类名? Any Idea?

Answer 1:

这应该这样做:

NSUInteger numberOfViewControllersOnStack = [self.navigationController.viewControllers count];
UIViewController *parentViewController = self.navigationController.viewControllers[numberOfViewControllersOnStack - 2];
Class parentVCClass = [parentViewController class];
NSString *className = NSStringFromClass(parentVCClass);


Answer 2:

获取类父视图控制器:

id class = [self.navigationController.viewControllers[0] class];

和它的名字:

NSString *className = NSStringFromClass(class);


文章来源: Get class name of Parent View controller in iPhone Navigation push