How to call a method in init method?
My program looks like this:
-(id)init
{
if ( (self = [super init]) )
{
//TargetWithActions *targetActions= [[TargetWithActions alloc] init];
[self countDownSpeed123];
}
return self;
}
-(void)countDownSpeed123
{
countDownSpeed = 5.0f;
}
@end
warning: 'TargetWithActions' may not respond to '-countDownSpeed123'
I am getting the warning in this way. Where I am wrong in my program. Please explain ? Thank You.
If I need to use the countDownSpeed value in another class, how can I retain the value ? How can I use in the other class? I think retain works for pointer types.
EDIT:
Sorry for my bad coding and negligence. I have did mistakes in my program which are very blunt.
Thanks for answering.
- First: I did not declare the
function (
-(void)countDownSpeed123;
)in interface. Second: I did not include the following in my class where I needed the (countDownSpeed) value.
TargetWithActions *targetActions= [[TargetWithActions all开发者_Go百科oc] init]; [targetActions countDownSpeed123];
Now, I got what I need.
Thank You.
In the class where you trying to use
TargetWithActions
, and inTargetWithActions.m
make sure you have#import "TargetWithActions.h"
.In
TargetWithActions.h
make sure in your class declaration you declared the method-(void)countDownSpeed123;
Sorry I don't understand what are you trying to do with
countDownSpeed123
, it does not return anything (void) so I'm not quite sure what you want toretain
. If the method returns simple value likefloat
orint
you don't have to retain it, it is passed by value - it will be copied.
Sorry for my bad coding and negligence. I have did mistakes in my program which are very blunt. Thanks for answering. First: I did not declare the function ( -(void)countDownSpeed123; )in interface. Second: I did not include the following in my class where I needed the (countDownSpeed) value. TargetWithActions *targetActions= [[TargetWithActions alloc] init]; [targetActions countDownSpeed123]; Now, I got what I need. Thank You.
精彩评论