티스토리 뷰
네트웍을 통한 데이터 송수신 등 시간이 걸리는 작업 시 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 |
betabuilder를 이용하여 ios Adhoc 배포시 주의사항 (0) | 2013.03.07 |
XCODE 4.6 업데이트 후 메소드 워닝 (0) | 2013.02.13 |
ios Custom Cell Row Height설정 (0) | 2013.02.06 |
- Total
- Today
- Yesterday
- 레인보우샤크
- simpleAdo
- C/C++
- 루드위지아
- 챔픽스
- 하이그로필라
- NAS
- 캠핑
- 쿠바펄
- 오토씽
- 루드위지아 오발리스
- 장기전세
- ADO
- 편도수술
- 램즈혼
- 마곡지구
- ixus75
- 미니헤어그라스
- 소설
- Mpow
- 산세베리아
- 채리새우
- 네온테트라
- 시내랑
- 미에어2
- 133인치
- 노랭이새우
- 금연
- 아쿠아스카이
- 수초어항
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |