在iPhone Navigation push中获取Parent View控制器的类名

时间:2013-04-02 09:08:55

标签: iphone ios uinavigationcontroller push

我正在推这样的观点。

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

如何从推送视图(子视图)获取父视图控制器的类名? Any Idea?

2 个答案:

答案 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);