조회 수 916 추천 수 0 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
57 Develop [c] 정사각배열의 서브 배열의 최대 값 구하기 file hooni 2003.04.23 7036
56 Develop [c] 단어 입력/수정 프로그램 소스 file hooni 2003.04.23 7042
55 Develop [c] 농구팀 점수 산출 프로그램 소스 file hooni 2003.04.23 7401
54 Develop [자료구조] 트리(tree) 용어정리 file hooni 2003.04.23 11095
53 Develop [c] 이진트리(binary tree)의 특성 file hooni 2003.04.23 9626
52 Develop [c] 이진트리(binary tree)의 운행.. hooni 2003.04.23 8288
51 Develop [c] 근의 공식으로 2차방정식 풀기.. file hooni 2003.04.23 7800
50 Develop [c] 학생명단 관리 프로그램 소스 ㅋㅋ 1 file hooni 2003.04.23 7794
49 Develop [jsp][php] 간단한 강좌 자료.. file hooni 2003.04.23 8131
48 Develop [c] flooding 알고리즘 미로 찾기(도스용) 소스코드 9 file hooni 2003.04.23 12571
47 Develop [c] 테트리스(Tetris) 게임(도스용) 소스코드 file hooni 2003.04.23 11502
46 Develop [c] 파일입출력, 링크리스트(linked list)를 이용한 주소록(도스용) 소스코드 1 file hooni 2003.04.23 11180
45 Develop [c] 간단한 자료구조(stack, queue, linked list) 구현 소스 6 file hooni 2003.04.23 10146
44 Develop [unix] 쉘 스크립트 예제 모음 hooni 2003.04.23 15000
43 Develop [linux] 쉘 스크립트를 이용한 BBS hooni 2003.04.23 10074
42 Develop [c] pcap을 이용한 패킷 분석 ㅎㅎ hooni 2003.04.23 10235
Board Pagination Prev 1 ... 48 49 50 51 52 53 Next
/ 53