获取微调的观点在我的应用程序加载

问题描述:

尽快开始,我有一个表在viewControllers之一。当其中一行被点击时,它会将用户转到不同的视图/视图控制器,并且它可以工作。在这个新的viewController中,数据正在从后台的php脚本解析。获取微调的观点在我的应用程序加载

这大约需要7-10秒,在这个时候,我希望用户立即看到一个微调,上面写着“中..”。我有这个实现自己,但微调不启动加载到4-5秒。在此期间,屏幕是完全冻结,我不能挖掘任何东西,直到显示旋转/数据回去。

我试图把下面的代码放在实际获取数据的方法中,同时在两个(而不是同一时间)viewDidAppear和ViewDidLoad方法,但同样的事情发生。

如果有人知道如何解决这个问题,这将是大加赞赏。

谢谢

[web loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://xxx.xx.xx.xxx/stuff/xxx.php"]]]; 

    [web addSubview:spinner]; 

    timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector: @selector(tick) userInfo:nil repeats:YES]; 


    load_message = [[UIAlertView alloc] initWithTitle:@"Loading..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil]; 

    spinner= [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    spinner.center = CGPointMake(135.0, 60.0); 
    [load_message addSubview:spinner]; 




-(void) tick 
{ 

if(!web.loading) 
{ 
    [spinner stopAnimating];  
    [load_message dismissWithClickedButtonIndex:0 animated:TRUE]; 



} 

else { 

    [load_message show]; 
    [spinner startAnimating]; 
} 



} 

你可以开始那么你的微调延迟后启动漫长的过程:

- (void)someMethod 
{ 
    [spinner startAnimating]; 
    [self [email protected](doLongProcess:) withObject:someObject afterDelay:0.0]; 
} 
- (void)doLongProcess:(id)someObject 
{ 
    //Some really long process 
} 

你的微调最有可能阻止,因为一个漫长的过程可以在同一线程上发生。

+0

谢谢你的回复杰里米。我会在哪里调用某种方法?在viewDidAppear?因为在那之前,我正在呼吁我的长期处理方法。谢谢 – Teddy13 2012-01-05 06:22:43

+0

Nvm我解决了它。谢谢! – Teddy13 2012-01-05 06:42:07

你要做下列之一(假设你把你的web请求在一个名为“startWebRequest”的方法):

  1. 启动UIActivityIndi​​catorView上的主UI线程(如果尚未从主线程运行):

    [self performSelectorOnMainThread:@selector(startWebRequest)withObject:nil waitUntilDone:NO];

  2. 开始在后台线程web请求:

    [自performSelectorInBackground:@selector(startWebRequest)withObject:无];

  3. 暂停等的第二1/10开始像web请求之前:

    [的NSTimer scheduledTimerWithTimeInterval:0.1F目标:自选择器:@selector(startWebRequest)USERINFO:无重复:NO];

+0

谢谢耶书亚...那工作以及 – Teddy13 2012-01-05 06:42:25

+0

不是一个大问题,但我回答6小时杰里米之前,我想我的答案是更完整的很好的建议。 – 2012-01-05 17:57:22