Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSTimer problems...

NSTimer problems...
Thread Tools
Fresh-Faced Recruit
Join Date: May 2001
Location: Salt Lake City, UT, USA
Status: Offline
Reply With Quote
May 23, 2001, 09:25 PM
 
I can't seem to start an NSTimer. Here is my simple example, and hopefully someone can help me out....

I have a subclass of NSView which has a NSTimer property. It overrides initWithFrame which does:

<code>
NSRunLoop *r=[NSRunLoop currentRunLoop];

[super initWithFrame:frameRect];

timer=[NSTimer timerWithTimeInterval:2 target:self selector:@selector(nextFrame userInfo:nil repeats:YES];

[r addTimer:timer forMode:[r currentMode]];
return self;
</code>

Now the nextFrame: method is there and works (it just executes NSBeep()). It segfaults on [r currentMode] (I assume because it return nil). And I don't understand what the forMode: argument is. Regardless, if I just make up a string (ie @"") the method is never called.

Hopefully someone understands what's wrong here.

Thanks!!
Jeff
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
May 24, 2001, 08:32 AM
 
I have used NSTimer before without any trouble. I don't remember how I added it to a run loop other than the default one, but you are just adding the timer to the default one so it's no big deal. just use:

scheduledTimerWithTimeInterval:invocation:repeats:
or
scheduledTimerWithTimeInterval:target:selector:use rInfo:repeats:

They automatically register the new timer with the current NSRunLoop object in the default mode.
     
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
May 24, 2001, 02:20 PM
 
From looking at the docs, forMode: expects one of the following:
NSDefaultRunLoopMode
NSConnectionReplyMode
NSModalPanelRunLoopMode
NSEventTrackingRunLoopMode

Hope that helps.
     
Junior Member
Join Date: Mar 2001
Status: Offline
Reply With Quote
May 24, 2001, 03:47 PM
 
Consider putting the timer initializaion in the awakeFromNib method instead of initWithFrame:. The run loops may not be established when initWithFrame: is called.

-Peter
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:14 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2