我有这个函数,它调用一个函数来检查CMS的信息。但是UIActivityIndicatorView会一直冻结,直到检查完成。不知道为什么。
编辑:有趣的是,我注释掉了性能选择器。UIActivityIndicatorView仍然冻结。直到我按下后退按钮,它才开始旋转...
我使用的是故事板,iOS 5
-(void)showLoading
{
[activity startAnimating];
//loading is a label to show "File Loading"
loading.alpha =1;
//is a label to show a 0.3 alpha of the label
blackOverlay.hidden =0;
[self performSelector:@selector(updateFromInternet:) withObject:@"a" afterDelay:2];
//[self updateFromInternet:@"a"];
}
-(void)updateFromInternet:(NSString *)urlStr
{
NSString *URLString = @"http://sites.google.com/site/iphonesdktutorials/xml/Books.xml";
NSURL *updateDataURL = [NSURL URLWithString:URLString];
NSMutableURLRequest *WPXMLFetchRequest = [NSMutableURLRequest requestWithURL:updateDataURL];
self.receivedData = [NSMutableData data];
self.updateConnection = [NSURLConnection connectionWithRequest:WPXMLFetchRequest delegate:self];
NSLog(@"Checking update at : %@", updateDataURL);
//[self.updateConnection cancel];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
////NSlog(@"Receiving data");
[self.receivedData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
////NSlog(@"Failed to receive data");
self.receivedData = nil;
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
////NSlog(@"Received response from data");
[self.receivedData setLength:0];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *data=[[NSString alloc]initWithData:self.receivedData encoding:NSUTF8StringEncoding];
NSLog(@"data %@",data);
NSError *parseError = nil;
//NSDictionary *xmlDict = [XMLReader dictionaryForXMLData:self.receivedData error:&parseError];
self.receivedDict = [XMLReader dictionaryForXMLData:self.receivedData error:&parseError];
[self showDataOnScrollView];
}发布于 2012-03-01 20:33:46
你应该稍微延迟一下“重”函数,让活动指示器触发。尝试在延迟中添加2.0而不是2(我会使用一个小得多的值-比方说0.3)
[self performSelector:@selector(updateFromInternet:) withObject:@"a" afterDelay:0.3]; 如果这不能解决您的问题,您应该查看(或发布)与代码中包含的额外内容相关的代码,如: loading.alpha =1;和blackOverlay.hidden =0;我假设它们是添加到活动指示器中的元素
https://stackoverflow.com/questions/9515815
复制相似问题