Get class name of Parent View controller in iPhone

2019-04-06 05:38发布

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?

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-04-06 06:14

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);
查看更多
甜甜的少女心
3楼-- · 2019-04-06 06:15

Get class of parent view controller:

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

and its name:

NSString *className = NSStringFromClass(class);
查看更多
登录 后发表回答