ViewController和drawRect [英] ViewController and drawRect
问题描述
我有一个UIViewController,我想调用drawRect,所以我可以绘制视图,但没有任何反应。
I have a UIViewController and I would like it to call drawRect so i can draw on the view but nothing happens.
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
...code...
}
@end
和实现
#import "ViewController.h"
@implementation ViewController
-(void) drawRect:(CGRect) rect {
draw a pony
}
- (void)viewDidLoad {
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
应用程序运行时的视图,我做错了什么?
But no pony gets drawn on the view when the app is run, what do i do wrong?
推荐答案
UIViewController
没有覆盖消息 drawRect
。
您应该创建自 UIView
派生的自定义类,并覆盖 drawRect
。
The UIViewController
don't have overridden message drawRect
.
You should create custom class derived from UIView
and override message drawRect
there.
您可以为 UIViewController
覆盖(UIView *)视图
UIView
或在Interface Builder中将类从 UIView
更改为自己的类。
You can override message (UIView *)view
for UIViewController
and return own custom UIView
or in Interface Builder change class from UIView
to own class.
这篇关于ViewController和drawRect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!