Contents

Views 923 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
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
No. Category Subject Author Date Views
685 Develop [c++] 헤더, 소스 파일 분리해서 작성해본 테스트 소스 file hooni 2013.04.23 6715
684 Develop [c++] 현승이가 준 P2P 프로그램 소스 ㅋㅋ file hooni 2013.04.23 12100
683 Develop [c++] 현승이가 준 메신저 소스.. ㅋㅋ file hooni 2013.04.23 8296
682 Develop [c++][mfc] 파일 입출력 샘플 (한줄씩 읽어서 다른 파일에 쓰기) hooni 2013.04.23 15040
681 Develop [c++]현승이가 보내준 동영상 암호화 자료.. 볼것.. file hooni 2003.04.23 9754
680 Develop [c++]현승이가 보내준 암호화 모듈 AES라인델.. file hooni 2003.04.23 10742
679 Develop [c/c++] Makefile 사용하기.. ㅋㅋ hooni 2003.04.23 7389
678 Develop [chm] C++ 문법 가이드 file hooni 2013.04.23 7966
677 Develop [chm] Programming Applications for Microsoft Windows file hooni 2013.04.23 7278
676 Develop [chm] 비주얼 C++ 팁 모음 문서 file hooni 2013.04.23 7518
675 Develop [chm] 윈도우즈에서 디버깅 기법(Debugging Applications) file hooni 2013.04.23 7547
674 Develop [coding] Find all anagrams in a string hooni 2017.06.27 1290
Board Pagination Prev 1 ... 9 10 11 12 13 14 15 16 17 18 ... 71 Next
/ 71