我已经看到了一个普通的 UIButton:
NSArray *actions = [viewController.addButton actionsForTarget:viewController forControlEvent:UIControlEventTouchUpInside];
XCTAssertTrue([actions containsObject:@”addNumbers:”], @””);
但现在我想为 rightBarButtonItem 做同样的事情!我在VC上测试过这个按钮存在但是没有actionForTargets接口!
我也试过这个,但没有奏效:
NSArray *actions = [self.navigationItem.rightBarButtonItem actionsForTarget:self forControlEvent:UIControlEventTouchUpInside];
或者
NSArray *actions = [[self.navigationItem.rightBarButtonItem target] actionsForTarget:self forControlEvent:UIControlEventTouchUpInside];
它们都不起作用。任何人都为 UIBarButton 编写了测试代码来检查按钮是否连接到正确的 IBAction?