Iphone Xcode错误消息-ViewController没有可见的@interface声明选择器

Iphone Xcode错误消息-ViewController没有可见的@interface声明选择器,iphone,objective-c,ios,xcode,uibutton,Iphone,Objective C,Ios,Xcode,Uibutton,我有一个非常简单的方法,允许我指定UIButton的名称,然后设置其标题。我以前在我的主ViewController中使用过该方法,效果很好。但是后来我决定创建一个名为CustomMethods.h/m的新文件,并将我所有的方法都放在其中 一旦我移动了方法并#将标题导入到主视图控制器中,我就会收到下面的错误消息 No visible @interface for ViewController declares the selector 'SetTitleOfButtonNamed:withTit

我有一个非常简单的方法,允许我指定UIButton的名称,然后设置其标题。我以前在我的主ViewController中使用过该方法,效果很好。但是后来我决定创建一个名为CustomMethods.h/m的新文件,并将我所有的方法都放在其中

一旦我移动了方法并#将标题导入到主视图控制器中,我就会收到下面的错误消息

No visible @interface for ViewController declares the selector 'SetTitleOfButtonNamed:withTitle:'
在CustomMethods文件中,我创建了如下方法:

-(void)setTitleOfButtonNamed:(UIButton *)button withTitle:(NSString *)buttonTitle
{
    [button setTitle:buttonTitle forState:(UIControlStateNormal)];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *btnOneTitle = @"Button 1";
    [self setTitleOfButtonNamed:buttonOne withTitle:btnOneTitle]; // ERROR OCCURS HERE
}
在主ViewController的viewDidLoad中,我尝试调用此方法并设置按钮标题,如下所示:

-(void)setTitleOfButtonNamed:(UIButton *)button withTitle:(NSString *)buttonTitle
{
    [button setTitle:buttonTitle forState:(UIControlStateNormal)];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *btnOneTitle = @"Button 1";
    [self setTitleOfButtonNamed:buttonOne withTitle:btnOneTitle]; // ERROR OCCURS HERE
}

在我将该方法复制到它自己的文件之前,它工作得非常好。有什么想法吗?

您仍然在调用视图控制器“self”上命名的SetTitleOfButton。您需要从现在实现该方法的CustomMethods类调用它

[self setTitleOfButtonNamed:buttonOne withTitle:btnOneTitle];

您仍在调用“self”上命名的SetTitleOfButtonName,它是ViewController。您需要从现在实现该方法的CustomMethods类调用它

[self setTitleOfButtonNamed:buttonOne withTitle:btnOneTitle];

不,对不起,这完全是一个问题中的错误。不,对不起,这完全是一个问题中的错误。谢谢!将方法更改为类方法而不是实例,并从定义它的类调用。很好用。请你再解释一下好吗?谢谢!将方法更改为类方法而不是实例,并从定义它的类调用。很好用。请你再解释一下好吗?