drawRect not being called
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!
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!
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........
Code:
#import "GameField.h"
@interface GameView : UIView {
IBOutlet GameField *controller;
}
@end
@implementation GameView
-drawRect
{
NSLog(@"Please please update me from GameField");
}
@class GameView;
@interface GameField : NSObject {
int fieldSize;
IBOutlet GameView *viewController;
}
@end
@implementation GameField
-someSelector
{
//here I want the View to redraw itself
[viewController setNeedsDisplay];
}=========
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........
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.
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:
Code:
- (void)drawRect:(CGRect)rectOr 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.
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?
Code:
- (void)drawRect:(CGRect)rectWhat 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?
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...
Send your message, that the view needs updating, then do
Code:
CFRunLoopRunInMode (CFRunLoopCopyCurrentMode(CFRunLoopGetCurrent()), 0, FALSE);This forces the update on your view.
Hope it works for you...
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Taking advantage of 3DNow, SSE, MMX or whatever the PPC equivalent is called... | Jones | 3 | 3,152 |
Oct 24, 2006 07:06 AM Last Post: Jones |
|
| drawRect in NSOpenGLView help | fakeOne | 3 | 3,683 |
Sep 3, 2006 09:04 AM Last Post: Xenos |
|
| drawRect: is not executed after setNeedsDisplay:YES | Moridin | 7 | 6,601 |
Oct 19, 2005 12:42 AM Last Post: Moridin |
|
| drawRect before awakeFromNib | unknown | 4 | 4,029 |
Aug 25, 2005 04:17 PM Last Post: unknown |
|
| drawRect without resetting the NSView | jspoon | 4 | 3,397 |
Apr 1, 2005 09:38 AM Last Post: jspoon |
|

