DrawRect does not get called in a simple customized UIView
In the code below, my drawRect method is never called. Note tht HypnosisView is inherited from UIView. Can some experts here help me out? Thanks a lot!
- (void)drawRect:(CGRect)rect
{
// This code is never getting called....
NSLog(@"in drawRect...");
// Drawing code -- no need to post this since this function is not even getting called
}
@end
Below is the code I created the view and added it to the current window...
- (BOOL)application:(UIApplication *)applicat开发者_JAVA技巧ion didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
CGRect wholeWindow = CGRectMake(0,0,320,460); //[window bounds];
view = [[HypnosisView alloc] initWithFrame:wholeWindow];
[view setBackgroundColor:[UIColor clearColor]];
[window addSubview:view];
[view setNeedsDisplay];
[self.window makeKeyAndVisible];
return YES;
}
The most likely cause is that window
is nil
. Make sure it's correctly bound in Interface Builder.
精彩评论