Reputation: 4984
I have an iPad app (XCode 5, iOS 7, Storyboards and ARC). I have a UIPopover
created in a UIViewController
, and when I tap a button it correctly displays the popover.
Now, I want to draw a grid in that popover; I know I have to add code to drawRect
do do the drawing, and do a setNeedsDisplay
to get the drawing done. However, it's not working!
My question is why is drawRect
not being called when from [popoverView setNeedsDisplay];
? Both methods are in the same UIViewController class.
Here is the code that is supposed to call the drawRect
// create popover
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView *popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 650, 416)];
popoverView.backgroundColor = [UIColor whiteColor];
popoverContent.preferredContentSize = CGSizeMake(650.0, 416.0);
// draw the lines, etc on the popoverContent
[popoverView setNeedsDisplay];
// create the popover controller and attach the popover content to it
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate = (id)self;
[popoverController setPopoverContentSize:CGSizeMake(650, 416) animated:NO];
[popoverController presentPopoverFromRect:CGRectMake(650, 416, 10, 50) inView: obViewOpenAppts
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
I have a breakpoint in drawRect
so I know it's not being called.
What am I doing wrong?
Upvotes: 0
Views: 581
Reputation: 66292
drawRect:
is a UIView method, not a UIViewController method. If you want to override it you have to subclass UIView, and then create it like this:
MyUIViewSubclass *popoverView = [[MyUIViewSubclass alloc] initWithFrame:CGRectMake(0, 0, 650, 416)];
Upvotes: 4