- Hook respondsToSelector: interface. For example, the name of the hooked interface is yy_respondsToSelector: 2. Use the passed parameter aSelector in yy_respondsToSelector. The sample code is as follows:
(BOOL) yy_respondsToSelector:(SEL)aSelector { if ([self yy_respondsToSelector:aSelector]) { return YES; } if ([self.selectorNameArray containsObject:NSStringFromSelector(aSelector)]) { return YES; } return NO; } 2. In a custom UIViewController, such as YYViewController, implement the following code (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSMutableArray *vcs = [[NSMutableArray alloc]init]; [vcs addObject:[[UIViewController alloc] init] ]; [vcs addObject:[[UIViewController alloc] init] ]; self.navigationController.viewControllers = vcs; } 3. When the page YYViewController is loaded and viewDidAppear is executed, App There will definitely be a crash, because aSelector is an illegal pointer, and access will crash