On Aug 20, 2008, at 11:08 AM, Joseph Kelly wrote:


On Aug 20, 2008, at 7:25 AM, Charlie Dickman wrote:

I have an app that contains multiple NSView's which are all visible at the same time. They are all sub-classes of NSView but not of any of the others. Each has its initialize, initWithRect and drawRect methods invoked as it should.

With the exception of the 1st one I defined, the workhorse view, no methods implemented in any of the others and declared in the respective .h files are visible to any of the other views at compile time. I import the appropriate .h files and invoke the method via [view method... and the compiler reports that no such method can be found. Yet if I invoke the method via [view performSelector:... at execution time it works just fine.

Sounds like a declaration issue :-)

That may be what it sounds like but I've tried every which way I can to declare it differently to no avail.


You get a compile error with:

[view method];

What type is "view", and does "method" contain a typo? Like maybe it's "mehtod" or maybe it requires an argument "method:YES"? I know this sounds pedantic, but we've all banged our heads around really dumb errors.

"view" is an NSView and method is not spelled wrong. As I said, I can call it just fine with [view performSelector at run-time.


There are cases where I've got a pointer to a superclass, but I know it's really a particular subclass, and I will simply cast the pointer to the subclass:

NSView* obj = something;
if ([obj respondsToSelector:@selector(method:withThingy:)])
[(MyViewClass*) obj method:YES withThingy:something]; // Shut up, compiler.

Either way, what you want to do is post a snippet of the offending code, including variable declarations.



Also, how does one synchronize events with the update of the various views? I can instruct each view what to draw and it draws it just fine (I use lockFocus, etc. when drawing is external to drawRect) and the updated view is seen _eventually_ but I can not synchronize subsequent activity to happen after the appropriate display is seen. How can I accomplish this synchronization? And how can I force a view to update? Invoking [view display] has no effect on forcing the display toshow the latest update.

Calling [view setNeedsDisplay:YES] is the most common way of updating. Unless you're writing a 2d game, you'll want to use this 95% of the time. It flags the view for an asynchronous draw at a time when the event loop is idle, and I believe it is syncd up to the vbl. If drawing via this method is inefficient -- i.e. there's noticeable delay between when you call it and when you draw, this means either your drawInRect is using too much cpu, or your main thread is using too much cpu. Run Shark.app and see where the time is being spent.

If you get your heavy processing out of the way and your drawing code is streamlined and it's still taking too long, then you could use [view display]; -- this does a synchronous draw + flush, also sync'd to the vbl, so it potentially could block your main thread up to 0.16 seconds, which is very bad.

See 
https://developer.apple.com/documentation/Performance/Conceptual/Drawing/DrawingPerformance.html

So why are you calling lockFocus?

I call lock focus whenever I'm drawing outside the purview of drawRect. This is the way the documentation says to do it.

And I am writing a 2d game and things that need to be clicked on are constantly being updated but the display does not match the internal game conditions so the appropriate objects can not be selected.


Charlie Dickman
[EMAIL PROTECTED]



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to