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 > Forced NSView redraw

Forced NSView redraw
Thread Tools
Mac Enthusiast
Join Date: Jan 2001
Status: Offline
Reply With Quote
May 4, 2001, 02:28 PM
 
So I have a function that does something, uses NSTimer to pause for a short time and repeat. During that loop, i want my NSView to update, is there any way to do this?

Thanks
     
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
May 4, 2001, 02:39 PM
 
Supposing that you are overriding the drawRect method to implement the drawing, you could simply pass the NSView instance the display message. Since all NSViews have this it can be used to force a redraw directly (it is usually invoked indirectly by setNeedsDisplay, or something).

Example:
[myNSView display];

You should be able to call this directly from the NSTimer but I am not sure. Another topic discussed this and there was talk that it could not find it since it is not defined in your specific subclass. In that case just make something that calls display.

Example:
-(void)thingThatDoesStuff
{
[self display];//if this is being defined in the same class as the NSView subclass you are using or...
[myNSView display];//if you are defining this NSTimer "target" in another class.
}

Hope that helps,
Jeff.
Spectral Class
"Shedding Light on Innovation"
     
tie
Professional Poster
Join Date: Feb 2001
Status: Offline
Reply With Quote
May 4, 2001, 04:57 PM
 
Be careful calling display from the Timer. Most of the time it will work correctly, but is possible that your application will hang because the window drawing code is not thread safe. There are two cases:

If the timer is in the main thread, then you could have an error if another method tried to display the same view. This is pretty easy to avoid.

If the timer is in a separate thread, you'll have lots of errors. You would have a problem, for example, if the timer fired just as the user clicked on a menu.

Calling setNeedsDisplay(inRect) is much safer.
The 4 o'clock train will be a bus.
It will depart at 20 minutes to 5.
     
   
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 09:57 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