传递类型为UITextDelegate的ViewController作为参数

时间:2014-08-15 06:39:37

标签: ios objective-c

我在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];
}

1 个答案:

答案 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 ...];

}