我有从UIViewController继承ClockViewController.h和ClockViewController.m。
另外2个文件ClockView.h和ClockView.m继承自UIView。在界面生成器中,我为时钟选择了类“ClockView”,但是我的drawRect没有执行。我通过定时器函数的setNeedsDisplay调用它。即使定时器功能没有调用。
这里是代码
ClockViewController.m
drawRect没有执行
import "ClockViewController.h"
@implementation ClockViewController
- (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 {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
[super viewDidUnload];
}
- (void)dealloc {
[super dealloc];
}
@end
这里是ClockView.m
import "ClockView.h"
@implementation ClockView
-(id)initWithCoder:(NSCoder *)coder{
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(clockTick) userInfo:nil repeats:YES];
return self;
}
-(id)initWithFrame: (CGRect)frame{
if(self = [super initWithFrame: frame]){
//Initialization code
}
return self;
}
-(void) drawRect: (CGRect)rect{
NSLog(@"from Rect");
}
-(void)clockTick{
NSLog(@"test");
}
-(void)dealloc{
[super dealloc];
}
@end
任何代码? _____ – kennytm 2010-05-29 08:37:37