我有这个函数,它调用一个函数来检查 CMS 的信息。但 UIActivityIndicatorView 卡住直到检查完成。不知道为什么。
编辑:有趣的是,我注释掉了 performselector。 UIActivityIndicatorView 仍然卡住。直到我点击后退按钮然后它开始旋转....
我正在使用 Storyboard,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];
}
最佳答案
您应该稍微延迟“重”功能并让事件指示器触发。 尝试为您的延迟添加 2.0 而不是 2(我会使用更小的值 - 比如 0.3)
[self performSelector:@selector(updateFromInternet:) withObject:@"a" afterDelay:0.3];
如果这不能解决您的问题,您应该查看(或发布)与代码中的额外内容相关的代码,例如:loading.alpha =1;和 blackOverlay.hidden =0;我假设是添加到事件指示器中的元素
关于iphone - UIActivityIndicatorView 卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9515815/