[iPhone类代码] 简单的多线程调用

在主线程里加入一个loading画面……
  2 {
  3     [window addSubview:view_loading];
  4     [NSThread detachNewThreadSelector:@selector(init_backup:) toTarget:self withObject:nil];
  5 }
可以通过performSelectorOhMainThread更新UI元素,比如设置进度条等等。最后消除loading画面,载入主View。
  7 - (void)init_backup:(id)sender
  8 {
  9     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
10 
11     //  ...
12     int i = status;
13     [self performSelectorOnMainThread:@selector(show_loading:) withObject:[NSNumber numberWithInt:i] waitUntil    Done:NO];
14 
15     [view_loading removeFromSuperview];
16     [window addSubview:tabcontroller_main.view];
17     [pool release];
18 }

 

posted on 2012-11-15 18:10  无量少年  阅读(149)  评论(0编辑  收藏  举报

导航