drawRect not being called - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: drawRect not being called (/thread-870.html)
drawRect not being called - IckyThump - Aug 12, 2009 02:11 AM
I have a Class View:UIView, inheriting from class Controller:NSObject. Class View is responsible for the view and the drawRect method is overridden there, to draw what I want.
Now I want to call setNeedsDisplay from class Controller, which doesn't know about View yet. So I have told it via @class View, that there is a class View, defined an IBOutlet of type View and made the connection in the Interface Builder.
There, I have an Object of Class Controller, and its Outlet referencing to View.
Still, when calling setNeedsDisplay on the outlet within the Controller class, drawRect is not called.
I can call drawRect from the View class without any problems wrong. I even checked the Outlet for being nil, and it also has its accessors synthesized.
Did I miss anything? Are the connections wrong?
Thanks in advance!
drawRect not being called - IckyThump - Aug 12, 2009 06:12 AM
I've decided to add some Code, maybe it helps.
In Interface Builder I have connected the Outlets, one from GameField to GameView and the other vice versa.
Now the GameView accesses the data in GameField correctly, theres no problem. But I cant access the GameView from the GameField - drawRect is not called. Why not? I have done everything in the same way-.... one works, the other doesn't........
drawRect not being called - maximile - Aug 12, 2009 07:43 AM
It's a bit confusing calling your GameView instance viewController, because there's a class called UIViewController. But that shouldn't affect how it works.
Are you sure your drawRect: method is correct? If you get it wrong it'll just call UIView's default implementation and your code will never get called, and there will be no compiler warning. It should be in the form of:
Or did you just shorten it to post here?
Also remember that setNeedsDisplay doesn't call drawRect: immediately, it waits until it returns to the run loop. If you're doing anything odd like running in your own loop it'll never get called.
drawRect not being called - IckyThump - Aug 12, 2009 07:52 AM
yes, sorry for the confusion. The Method is correct ->
What I do is, I check for a touch, i call a method from outside the class drawRect is in, to change some data. Within this method, I need the view to be redrawn, thats why I call setNeedsDisplay.
It seems like it's outside the main thread..... what to do?
drawRect not being called - IckyThump - Aug 13, 2009 06:48 AM
Fot anyone still interested in this topic:
Send your message, that the view needs updating, then do
This forces the update on your view.
Hope it works for you...