简体   繁体   English

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

[英]Xcode Error Message - No visible @interface for ViewController declares the selector

I have a very simple method that allows me to specify the name of a UIButton and then set its title. 我有一个非常简单的方法,允许我指定UIButton的名称,然后设置其标题。 I previously had the method in my main ViewController which worked fine. 我以前在我的主ViewController中使用了该方法,该方法运行良好。 But then I have decided to create a new file called CustomMethods.h/m and put all of my methods in there. 但是后来我决定创建一个名为CustomMethods.h / m的新文件,并将所有方法都放在其中。

As soon as I have moved the method across and #import the header into the main view controller I am getting the error message below 一旦我跨过方法并将#header导入到主视图控制器中,我将收到以下错误消息

No visible @interface for ViewController declares the selector 'SetTitleOfButtonNamed:withTitle:'

In my CustomMethods file I have created my method as follows: 在我的CustomMethods文件中,我创建了如下方法:

-(void)setTitleOfButtonNamed:(UIButton *)button withTitle:(NSString *)buttonTitle
{
    [button setTitle:buttonTitle forState:(UIControlStateNormal)];
}

In the viewDidLoad of the main ViewController I am trying to call this method and set the button title as follows: 在主ViewController的viewDidLoad中,我试图调用此方法并按如下所示设置按钮标题:

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

Before I copied the method into its own file it worked perfectly. 在将方法复制到其自己的文件中之前,它可以完美地工作。 Any ideas? 有任何想法吗?

You are still calling setTitleOfButtonNamed on "self" which is the ViewController. 您仍在对“自我”(即ViewController)调用setTitleOfButtonNamed。 You need to call it from the CustomMethods class that implements the method now. 您需要从现在实现该方法的CustomMethods类中调用它。

[self setTitleOfButtonNamed:buttonOne withTitle:btnOneTitle];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 xcode错误:masterViewController没有可见的@interface声明选择器 - xcode error: No visible @interface for masterViewController declares the selector &#39;NSData&#39;没有可见的@interface声明选择器 - No visible @interface for 'NSData' declares the selector &#39;DDExpression&#39;没有可见的@interface声明选择器&#39;evaluateWithSubstitutions:error:&#39;错误 - No visible @interface for 'DDExpression' declares the selector 'evaluateWithSubstitutions:error:' error iOS编译错误:'CDVCommandDelegateImpl'没有可见的@interface声明选择器'execute:' - iOS compile error: no visible @interface for 'CDVCommandDelegateImpl' declares the selector 'execute:' iOS编译错误:“ setLocationManager”没有可见的@interface声明选择器 - iOS compile error: No visible @interface for 'setLocationManager' declares the selector iOS错误:&#39;Project&#39;没有可见的@interface声明选择器&#39;alloc&#39; - iOS error: No visible @interface for 'Project' declares the selector 'alloc' &#39;BlahDataController&#39;没有可见的@interface声明选择器&#39;aMethod: - No visible @interface for 'BlahDataController' declares the selector 'aMethod: &#39;FirstViewController&#39;没有可见的@interface声明选择器&#39;setUIImage&#39; - No visible @interface for 'FirstViewController' declares the selector 'setUIImage' uinavigationcontroller没有可见的接口将选择器pushnavigationitem声明为动画 - no visible interface for uinavigationcontroller declares the selector pushnavigationitem animated 'NSObject <PageControlDelegate>'没有可见的@interface声明选择器'pageControlPageDidChange:' - No visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM