开发者

How to call a method in init method?

开发者 https://www.devze.com 2022-12-25 04:41 出处:网络
My program looks like this: -(id)init { if ( (self = [super init]) ) { //TargetWithActions *targetActions= [[TargetWithActions alloc] init];

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.

  1. First: I did not declare the function ( -(void)countDownSpeed123; )in interface.
  2. 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.


  1. In the class where you trying to use TargetWithActions, and in TargetWithActions.m make sure you have #import "TargetWithActions.h".

  2. In TargetWithActions.h make sure in your class declaration you declared the method -(void)countDownSpeed123;

  3. 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 to retain. If the method returns simple value like float or int 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号