문씨 강좌 참고 햇음
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];///스레드 멈춤
'아이폰' 카테고리의 다른 글
아이폰 언어 지역화 방법 (0) | 2012.07.11 |
---|---|
xcode 4.x에서 좀비 모드 설정하기 (0) | 2012.07.10 |
Objective c 정리 (0) | 2011.07.01 |
UITableView 기본 세팅 값들 (0) | 2011.07.01 |
WindowBased로 생성한 프로젝트에 UIViewController붙이기 UINavigationController 붙이기 아이폰 (0) | 2011.06.30 |