xtDelegate类型的ViewController作为参数传

xtDelegate类型的ViewController作为参数传

我在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/

10-09 02:22