2011. 10. 19. 10:40 아이폰



문씨 강좌 참고 햇음
http://cafe.naver.com/mcbugi


스레드 돌릴때 스레드 안에서 UI처리할때 에러 나는 상황의 처리 방법


//스레드 돌아라고할때 명령어

NSThread *_thread = [[NSThread alloc]initWithTarget:self selector:@selector(_th) object:nil];
[_thread start];//스레드 시작
/////////////////////////////////

-(void)_th{
//NSString 생성에 오토릴리즈가 포함 되어있기 때문에
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
int count = 0 ;
while([[NSThread currentThread]isCancelled]==NO)
{
count ++;
NSString *t = [NSString stringWithFormat:@"%i",count];
//메인스레드에서 그리는 부분은 새로 생성된 스레드에서 처리 할 수없다
[self performSelectorOnMainThread"@selector(mainThreadSetText:) withObject:t waitUntilDone:YES];
[NSThread sleepForTimeInterval:1.0];
}
[pool release];
}
-(void)mainThreadSetText:(NSString *)text{
_Label.text = text;
}

[_thread cancel];///스레드 멈춤

posted by 욱이다