Objective c 为什么不从ViewController调用*drawRect*?
我有一个iPad应用程序(XCode 5、iOS 7、故事板和ARC)。我在Objective c 为什么不从ViewController调用*drawRect*?,objective-c,ios7,drawrect,uipopover,Objective C,Ios7,Drawrect,Uipopover,我有一个iPad应用程序(XCode 5、iOS 7、故事板和ARC)。我在UIViewController中创建了一个UIPopover,当我点击按钮时,它会正确显示popover 现在,我想在那件府绸上画一个网格;我知道我必须将代码添加到drawRect进行绘图,并执行setNeedsDisplay以完成绘图。但是,它不起作用 我的问题是为什么从[popoverView setNeedsDisplay]调用drawRect时没有调用它?这两个方法位于同一UIViewController类中
UIViewController
中创建了一个UIPopover
,当我点击按钮时,它会正确显示popover
现在,我想在那件府绸上画一个网格;我知道我必须将代码添加到drawRect
进行绘图,并执行setNeedsDisplay
以完成绘图。但是,它不起作用
我的问题是为什么从[popoverView setNeedsDisplay]调用drawRect
时没有调用它代码>?这两个方法位于同一UIViewController类中
下面是应该调用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];
我在drawRect
中有一个断点,所以我知道它没有被调用
我做错了什么?drawRect:
是UIView方法,而不是UIViewController方法。如果要覆盖它,必须将UIView子类化,然后按如下方式创建它:
MyUIViewSubclass *popoverView = [[MyUIViewSubclass alloc] initWithFrame:CGRectMake(0, 0, 650, 416)];
drawRect:
是UIView方法,而不是UIViewController方法。如果要覆盖它,必须将UIView子类化,然后按如下方式创建它:
MyUIViewSubclass *popoverView = [[MyUIViewSubclass alloc] initWithFrame:CGRectMake(0, 0, 650, 416)];
是的,它正在调用默认实现,您没有覆盖它。您刚刚在UIViewController中创建了一个名为drawRect的方法:。您没有重写[UIView-drawRect:
,因为UIView不是UIViewController。对。。。我刚看到。。。这是一个缓慢的早晨…:这是我的接口代码,我在重写@interface CalendarViewController:UIViewController{}时遇到了问题(我不经常这么做)。这是你的UIViewController接口。如果您想创建一个UIView子类,那么创建一个新的file.Right,它将调用默认的实现,您不会覆盖它。您刚刚在UIViewController中创建了一个名为drawRect的方法:。您没有重写[UIView-drawRect:
,因为UIView不是UIViewController。对。。。我刚看到。。。这是一个缓慢的早晨…:这是我的接口代码,我在重写@interface CalendarViewController:UIViewController{}时遇到了问题(我不经常这么做)。这是你的UIViewController接口。如果要创建UIView子类,请创建一个新文件。我看到您正在创建popoverView,但没有看到您将其设置为任何内容的视图。我看到您正在创建popoverView,但没有看到您将其设置为任何内容的视图。