2010-04-02 102 views
1

我的計劃是這樣的:如何在init方法中調用方法?

-(id)init 
{ 
    if ((self = [super init])) 
    { 
     //TargetWithActions *targetActions= [[TargetWithActions alloc] init]; 
     [self countDownSpeed123]; 
    } 
    return self; 
} 
-(void)countDownSpeed123 
{ 
    countDownSpeed = 5.0f; 
} 
@end 

警告:「TargetWithActions」不能爲「-countDownSpeed123」

我收到這樣的警告做出迴應。我的程序中哪裏出錯了。請解釋 ? 謝謝。

如果我需要在另一個類中使用countDownSpeed值,該如何保留該值?我如何在其他課堂上使用?我認爲保留適用於指針類型。

編輯:

對不起,我的壞的編碼和疏忽。我的程序中犯了一些非常直截了當的錯誤。

感謝您的回答。

  1. 第一:我沒有 接口聲明 功能( -(void)countDownSpeed123;)。
  2. 第二:我沒有在我的課程中包含 以下需要 (countDownSpeed)值。現在

    TargetWithActions *targetActions= [[TargetWithActions alloc] init]; 
    [targetActions countDownSpeed123]; 
    

,我得到了我所需要的。

謝謝。

+2

您是否記得在界面中聲明「countDownSpeed123」? – 2010-04-02 05:41:20

+0

需要比這更多。請提供界面,而不僅僅是實現。 – 2010-04-02 05:42:57

+0

對不起,我忘了在界面中聲明它。 謝謝。編寫該方法的更好方法是哪一種。使用(id)或(void)? – 2010-04-02 05:48:25

回答

3
  1. 在類,你試圖使用 TargetWithActions,並在TargetWithActions.m確保您 有#import "TargetWithActions.h"

  2. TargetWithActions.h確保 在類聲明 你聲明的方法-(void)countDownSpeed123;

  3. 對不起,我不明白什麼是你想用countDownSpeed123做的,它不返回任何東西(空),所以我我不太清楚你想要什麼retain。如果方法返回簡單值,如floatint,則不必保留該值,它將按值傳遞 - 將被複制。

0

對不起,我的錯誤編碼和疏忽。我的程序中犯了一些非常直截了當的錯誤。謝謝回答。 第一:我沒有在接口中聲明函數( - (void)countDownSpeed123;)。 第二:我沒有在我的課程中包含以下內容,我需要(countDownSpeed)值。 TargetWithActions * targetActions = [[TargetWithActions alloc] init]; [targetActions countDownSpeed123]; 現在,我得到了我所需要的。 謝謝。

相關問題