Contents

조회 수 924 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
IOS SDK에서는 UI 의 접근을 Main Thread에서 만 허용하고 있습니다.
그래 다음과 같은 코드를 실행하면 UI가 업데이트 되지 않는데요.
- (void)thread_function
{
    for (; ;) {
        textView.text = @"hello";
    }
}

-(void)StartRecvThread
{
    [NSThread detachNewThreadSelector:@selector(thread_function)
        toTarget:self withObject:nil];
}

textView가 업데이트 되지 않습니다.

이럴 때에는 performSelectorOnMainThread를 이용하여 메인 쓰레드로 접근하는 방법이 있습니다.
[textView performSelectorOnMainThread:@selector(setText:)
    withObject:[NSString stringWithFormat:@"Thread count: %d ", count]
    waitUntilDone:YES];

이런 식으로 사용하면 되는데요.

위의 예제를 수정하면 다음과 같습니다.
- (void)thread_function
{
    for (; ;) {
        [textView performSelectorOnMainThread:@selector(setText:)
            withObject:@"hello" waitUntilDone:YES];
    }
}

한편 timer를 설정하는 접근 하는 방법도 있습니다.
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
    target:self selector:@selector(processUpdate:) userInfo:nilrepeats:YES];

-(void)processUpdate:(NSTimer *)theTimer
{
    textfield1.text =
        [NSString stringWithFormat:@"Thread count: %d ", count];
}

이런 식으로 하면 되겠지요.

[출처] http://www.digipine.com/programming/6779/page/2

?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
817 Develop [Xcode] 디버깅 옵션 file hooni 2013.04.23 57261
816 Develop [vb] 비주얼 베이직 205페이지 hooni 2003.04.23 56137
815 Develop [vb] 비쥬얼 베이직 기출 문제 연습 hooni 2003.04.23 55241
814 Develop [vb] 비주얼 베이직 173페이지 hooni 2003.04.23 54915
813 Develop [vb] 비쥬얼 베이직 기출 문제 연습2 hooni 2003.04.23 54447
812 Develop [iphone] view에 대한 조사 ㅡ,.ㅡ; file hooni 2013.04.23 54117
811 Develop [vb] 비쥬얼 베이직으로.. hooni 2003.04.23 53132
810 Develop [android] GCM 사용하기 1 (GCM 서비스 신청하기) file hooni 2013.07.06 51424
809 Develop [android]개발 가이드 및 한글화 문서 file hooni 2013.04.23 47562
808 Develop [android] ArrayAdapter를 이용하여 출력하기 hooni 2013.04.23 47392
807 Develop [ios] UIAlertView 초간단 샘플 ㅎㅎ hooni 2013.10.14 46196
806 Develop [ios] 배열(NSArray) 연산과 간단한 애니메이션(split images) hooni 2013.10.31 45558
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 71 Next
/ 71