Contents

조회 수 2072 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
171 Develop [css] 스크롤바 안생기게 hooni 2003.04.23 11523
170 Develop [css] z-index에 설정할 수 있는 최대값? hooni 2013.12.20 15952
169 Develop [coding] 공부해야 하는거 ㅋㅋ secret hooni 2017.06.27 0
168 Develop [coding] Find all anagrams in a string hooni 2017.06.27 3850
167 Develop [chm] 윈도우즈에서 디버깅 기법(Debugging Applications) file hooni 2013.04.23 8549
166 Develop [chm] 비주얼 C++ 팁 모음 문서 file hooni 2013.04.23 8595
165 Develop [chm] Programming Applications for Microsoft Windows file hooni 2013.04.23 11000
164 Develop [chm] C++ 문법 가이드 file hooni 2013.04.23 8931
163 Develop [c/c++] Makefile 사용하기.. ㅋㅋ hooni 2003.04.23 8345
162 Develop [c++]현승이가 보내준 암호화 모듈 AES라인델.. file hooni 2003.04.23 11547
161 Develop [c++]현승이가 보내준 동영상 암호화 자료.. 볼것.. file hooni 2003.04.23 11049
160 Develop [c++][mfc] 파일 입출력 샘플 (한줄씩 읽어서 다른 파일에 쓰기) hooni 2013.04.23 16162
Board Pagination Prev 1 ... 52 53 54 55 56 57 58 59 60 61 ... 71 Next
/ 71