我有從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