开发者

The error of NSTimer

开发者 https://www.devze.com 2023-01-11 18:44 出处:网络
I add a NSTimer in the iphone application。When I run the application,it‘s failed。I have tracked it and found that it stop at “0x3050c3ad<+0013>call0x306aeaa5 ” and cann\'t go on in Debugger。

I add a NSTimer in the iphone application。When I run the application,it‘s failed。I have tracked it and found that it stop at “0x3050c3ad <+0013> call 0x306aeaa5 ” and cann't go on in Debugger。

If you know,please tell me what’s wrong with the application and how to solve it。

Thank you!

The code is:

NSTimer *m_heartBeatTimer;

@property(nonatomic, retain) NSTimer *m_heartBeatTimer;

@synthesize m_heartBeatTimer;


-(void)HeartBeatTimer:(NSTimer *)timer
{

  [csocket CloseSocket];

}

case PING:
        {
            [self SendDataToServer:"00" Type:PONG];

            if(m_heartBeatTimer != nil)
                [m_heartBeatTimer开发者_运维技巧 invalidate];
            m_heartBeatTimer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(HeartBeatTimer:) userInfo:nil 
                                                               repeats:NO];


        } break;


lqf,

First you should access the timer via self.m_heartBeatTimer since you declared it as retained in the @property declaration. If you don't use the self. prefix, you aren't using the setter and therefore you aren't retaining the timer like you specified in the @property declaration.

I have no clue what your obscure error message is, but I'm guessing it's memory related. Make sure you use that self. prefix and let me know if that works. If you actually had an error message of EXC_BAD_ACCESS output on the Run Console, please update your post with that so it's something people can work with.

-Rob

0

精彩评论

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