我在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];
}
最佳答案
您应将方法声明/定义为:
Util.h
+ (UIView *) getBackButtonAsSubViewForNavigationBar:(UIViewController *)targetView target:(SEL)targetAction;
Util.m
+ (UIView *) getBackButtonAsSubViewForNavigationBar:(UIViewController *)targetView target:(SEL)targetAction {
...
[button addTarget:targetView action:targetAction ...];
}
关于ios - 将UITextDelegate类型的ViewController作为参数传递,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25322243/