Xcode错误消息 - ViewController没有可见的@interface声明选择器
问题描述:
我有一个非常简单的方法,允许我指定UIButton的名称,然后设置其标题。我以前有我的主要ViewController中的方法工作正常。但后来我决定创建一个名为CustomMethods.h/m的新文件,并将所有方法都放在那里。Xcode错误消息 - ViewController没有可见的@interface声明选择器
只要我提出的方法和跨#进口头到主视图控制器我正在下面
No visible @interface for ViewController declares the selector 'SetTitleOfButtonNamed:withTitle:'
以我CustomMethods错误消息文件我已经创建我的方法如下:
-(void)setTitleOfButtonNamed:(UIButton *)button withTitle:(NSString *)buttonTitle
{
[button setTitle:buttonTitle forState:(UIControlStateNormal)];
}
在主视图控制器我试图调用此方法,并设置按钮标题如下的viewDidLoad中:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *btnOneTitle = @"Button 1";
[self setTitleOfButtonNamed:buttonOne withTitle:btnOneTitle]; // ERROR OCCURS HERE
}
在将方法复制到它自己的文件之前,它完美地工作。有任何想法吗?
答
您仍然在ViewController的“self”上调用setTitleOfButtonNamed。您需要从实现此方法的CustomMethods类中调用它。
[self setTitleOfButtonNamed:buttonOne withTitle:btnOneTitle];
+0
谢谢!将方法更改为类方法而不是实例,并从定义它的类中调用。完美的作品。 – 2012-07-19 00:00:27
没有对不起,这纯粹是在这个问题上的拼写错误。 – 2012-07-18 23:53:06