UITableView的预加载圈

时间:2012-05-14 08:38:05

标签: iphone objective-c asynchronous preloader

我搜索了很多论坛但没有找到,我的问题是那个

  

我需要从Web预加载一些数据以加载到UITableView。

我看到一些应用程序解决了这个问题,当显示UITableView时,他们将“等待圈”显示为模态视图,加载数据后隐藏此圈。

  1. 这样做有简单的解决方案吗?
  2. 我需要做什么?
  3. 我需要什么样的请求:synchronius或asynchronius?
  4. 如何显示此圈子,我是否需要显示animatedGif或者有内部/外部控制?

2 个答案:

答案 0 :(得分:0)

您需要为“等待圈”制作NSThread - (活动指标)。

1)主题How do I create an NSThread that isn't the main thread

2)活动指标How to use activity indicator view

答案 1 :(得分:0)

 - (void)showWaitingView {

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

CGRect frame = CGRectMake(90, 190, 32, 32);
UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[progressInd startAnimating];
progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

frame = CGRectMake(130, 193, 140, 30);
UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame];
waitingLable.text = @"Processing...";
waitingLable.textColor = [UIColor whiteColor];
waitingLable.font = [UIFont systemFontOfSize:20];;
waitingLable.backgroundColor = [UIColor clearColor];
frame = [[UIScreen mainScreen] applicationFrame];
UIView *theView = [[UIView alloc] initWithFrame:frame];
theView.backgroundColor = [UIColor blackColor];
theView.alpha = 0.7;
theView.tag = 999;
[theView addSubview:progressInd];
[theView addSubview:waitingLable];

[progressInd release];
[waitingLable release];

[window addSubview:[theView autorelease]];
[window bringSubviewToFront:theView];
[pool drain];
  }

 - (void)removeWaitingView {
UIView *v = [window viewWithTag:999];
if(v) [v removeFromSuperview];

}