我有这个函数调用函数来检查CMS的信息。但是UIActivityIndicatorView冻结直到检查完成。不知道为什么。
编辑:有一件事很有趣,我评论了performselector。 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];
}
答案 0 :(得分:2)
您应该稍微延迟“重”功能,并激活活动指示器。 尝试在延迟时添加2.0而不是2(我会使用更小的值 - 比如0.3)
[self performSelector:@selector(updateFromInternet:) withObject:@"a" afterDelay:0.3];
如果这不能解决您的问题,您应该查看(或发布)与您的代码中的额外内容相关的代码,如:loading.alpha = 1;和blackOverlay.hidden = 0;我假设是添加到活动指标的元素