我在Util.m
中有一个静态函数
+ (UIView *) getBackButtonAsSubViewForNavigationBar:(UIViewController *)targetView :(SEL)targetAction {
...
[button addTarget:targetView action:targetAction ...];
}
在MyViewController : UIViewController < UITextFieldDelegate >
内,我尝试将其用作
UIView * backBtn = [Util getBackButtonAsSubViewForNavigationBar:self targetAction:@selector(cancelOp)]
但是Xcode说:
没有知道选择器方法的类 'getBackButtonAsSubViewForNavigationBar:targetAction:
我错过了什么?
Util.h
+ (UIView *) getBackButtonAsSubViewForNavigationBar:(UIViewController *)targetView :(SEL)targetAction;
Util.m
+ (UIView *) getBackButtonAsSubViewForNavigationBar:(UIViewController *)targetView :(SEL)targetAction {
...
[button addTarget:targetView action:targetAction ...];
}
cancelOp如下:
- (IBAction)cancelOp:(id)sender {
[self dismissViewControllerAnimated:YES completion:Nil];
}
答案 0 :(得分:2)
您应该将/ define方法声明为:
Util.h
+ (UIView *) getBackButtonAsSubViewForNavigationBar:(UIViewController *)targetView target:(SEL)targetAction;
Util.m
+ (UIView *) getBackButtonAsSubViewForNavigationBar:(UIViewController *)targetView target:(SEL)targetAction {
...
[button addTarget:targetView action:targetAction ...];
}