uiview子类{
初始化方法
-(id)initWithFrame:(CGRect)frame{
初始化类变量
t=[test new];
}
//前台绘画
-(void)drawRect:(CGRect)rect{
可以访问t变量
if(t != nil){
获取context
}
}
//后台读取数据
-(void)read{
}
-(void)run{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
[self performSelectorOnMainThread:@selector(setNeedsDisplay) vithObject:nil waitUntilDon:NO];
[NSThread sleepForTimeInterval:0.5];
[pool drain];
}
-(void)start{
NSThread *drawUI=[[NSThread alloc] initWithTarget:self selector:@selector(run) object:nil];
[drawUI start];
NSThread *readn=[[NSThread alloc] initWithTarget:self selector:@selector(read) object:nil];
[readn start];
}
}
注意这个方法中的initWithFrame,如果不用这个方法初始化,重绘drawRect的时候类变量t的计数会为0.