当前位置: 代码迷 >> Iphone >> iphone多线程应用setNeedsDisplay重绘drawRect
  详细解决方案

iphone多线程应用setNeedsDisplay重绘drawRect

热度:66   发布时间:2016-04-25 06:27:46.0
iphone多线程使用setNeedsDisplay重绘drawRect
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.



  相关解决方案