Contents

Views 2068 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
1129 Develop [ios] 미스터피자(Mr.pizza) 어플 file hooni 2013.04.23 46875
1128 Etc 스파이웨어(BHO) 탐지하는 방법.. hooni 2013.04.23 46551
1127 Develop [android] ListView+ArrayAdapter 테스트 hooni 2013.04.23 46486
1126 Develop [android] ArrayAdapter 테스트 파일 ㅎㅎ hooni 2013.04.23 46285
1125 Develop [android] 화면 전환(가로/세로)시 설정 hooni 2013.04.23 44364
1124 Develop [java] 스트러츠(Struts) 세팅 ㅋㅋ file hooni 2013.04.23 44327
1123 Develop [c++] BHO 프로그램 동작 원리.. 간단하게.. hooni 2013.04.23 43921
1122 Etc [용어] POC, Pilot, BMT에 대한 IT 업계에서 통용되는 의미 hooni 2014.01.02 43216
1121 Develop [php] Laravel 5.4: Specified key was too long error file hooni 2017.12.04 42515
1120 System/OS [ms-sql] 서브스트링(substring), 프로시저(SP) 작성 예제 hooni 2013.04.23 42433
1119 System/OS [mac] 맥에서 APM(apache,php,mysql) 구성하기 hooni 2013.04.23 42392
1118 Etc [svn] 콘솔에서 svn 사용시 레티나용 이미지 add 안될 때.. hooni 2013.09.25 42112
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 99 Next
/ 99