네트웍을 통한 데이터 송수신 등 시간이 걸리는 작업 시 thread 및 Activity Indicator사용을 많이 합니다.
performselector로 인디케이터 돌리고 작업시킨 다음 indicator 핸들로 stop를 했더니 일반적인
경우에는 잘 작동하였으나 performselector가 해당 함수를 호출하기 전에 아래 작업이 모두 끝나고
indicator stopAnimation까지 호출되는 상황 발생. 그 늦게 발동한 indicator의 무한 뺑뻉이...
그래서 stop도 performselector로 호출.
아래는 작업한 소스코드
//
//
// Created by likehood on 12. 1. 30..
//
//in AppDelegate.h
@interface CAppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>
-(void) threadStartActivityIndicator:(UIActivityIndicatorView*) indi;
-(void) threadStopActivityIndicator:(UIActivityIndicatorView*) indi;
@end
// AppDelegate.m
-(void) stopActivityIndicator:(UIActivityIndicatorView*) indi
{
[indi stopAnimating];
[indi removeFromSuperview];
NSLog(@"STOP INDICATOR");
}
-(void) startActivityIndicator:(UIActivityIndicatorView*) indi
{
UIWindow* appWindow = [UIApplication sharedApplication].keyWindow;
indi.color = [[UIColor alloc] initWithWhite:0.5 alpha:1];// initWithRed:1 green:0 blue:0 alpha:1.0 ];
CGRect rectCenter=appWindow.frame;
rectCenter.size.height=rectCenter.size.height;
[indi setFrame:rectCenter];
[appWindow addSubview:indi];
[indi bringSubviewToFront:appWindow];
indi.hidesWhenStopped = YES;
[indi startAnimating];
NSLog(@"START INDICATOR");
}
//in using class .m
-(void) threadLoadList
{
UIActivityIndicatorView* indi=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
CNIAppDelegate* delegate = (CNIAppDelegate*)[[UIApplication sharedApplication] delegate];
[delegate performSelector:@selector(startActivityIndicator:) onThread:[NSThread mainThread] withObject:indi waitUntilDone:NO];
//
// thread code here
//
[delegate performSelector:@selector(stopActivityIndicator:) onThread:[NSThread mainThread] withObject:indi waitUntilDone:YES];
[NSThread exit];
}
- (void) loadList
{
[NSThread detachNewThreadSelector:@selector(threadLoadList) toTarget:self withObject:nil];
}
'개발' 카테고리의 다른 글
libvlc 기반 wrapping class VLCWrapper 동영상 재생문제 (0) | 2013.03.08 |
---|---|
DGPS, WAAS, MSAS (0) | 2013.03.08 |
ios 스레드 동작 중 Activity Indicator사용 (0) | 2013.03.07 |
betabuilder를 이용하여 ios Adhoc 배포시 주의사항 (0) | 2013.03.07 |
XCODE 4.6 업데이트 후 메소드 워닝 (0) | 2013.02.13 |
ios Custom Cell Row Height설정 (0) | 2013.02.06 |