2012-07-18 69 views
0

我有一個非常簡單的方法,允許我指定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 
} 

在將方法複製到它自己的文件之前,它完美地工作。有任何想法嗎?

+0

沒有對不起,這純粹是在這個問題上的拼寫錯誤。 – 2012-07-18 23:53:06

回答

3

您仍然在ViewController的「self」上調用setTitleOfButtonNamed。您需要從實現此方法的CustomMethods類中調用它。

[self setTitleOfButtonNamed:buttonOne withTitle:btnOneTitle]; 
+0

謝謝!將方法更改爲類方法而不是實例,並從定義它的類中調用。完美的作品。 – 2012-07-19 00:00:27

相關問題