2013-03-29 18 views
4

使用我連接到我的標籤:Xcode中如何使用IBOutlet中標記,而在功能

@property (weak) IBOutlet NSTextField *scoreBox; 

正確,和我試圖訪問它是這樣的:

void namedfunction(button) { 

    if (button == button) { 
     score = score + 100; 
     [scoreBox setIntValue:score]; 
     //^error 
    } 
} 

和我得到這個錯誤:

AppDelegate.m:52:10: Use of undeclared identifier 'scoreBox'

我做錯了什麼?

回答

5

使用

[_scoreBox setIntValue:score]; 

或者

[self.scoreBox setIntValue:score]; 

* 也檢查你用比較相同按鈕,結束了:button==button

編輯2:

當你的代碼是:

int perus(int nappi){ 

} 

將其更改爲:

- (NSInteger *)perus:(NSInteger *)nappi{ 
    //all should do inside, rest are OK. 
} 

編輯:

我不知道有關以下如發現這個here

* 我建議你切換到obj-c方法而不是使用C函數來處理這類事情。

一個C函數就是這樣,一段代碼不會附加到任何東西 其他。您的實例變量附加到每個Controller對象。 因此,當您調用printChatter()時,無法知道要使用哪個Controller的實例。你可以一個對象 變量添加到您的函數:

void namedfunction(const void *button, const void *appDele){ 
    NSTextField *myButton=[appDele scoreBox]; 
    .... 
} 

+0

我都嘗試:_scorebox和self.scorebox,但我得到了同樣的錯誤...... – Axuttaja

+1

@ user2225385:顯示完整的代碼AppDelegate.m和AppDelegate.h –

+0

有鏈接捕獲他們... http://tinypic.com/r/ncb4nn/6他們在芬蘭所以....(捕獲AppDelegate.h&。 m) – Axuttaja