iphone - UIActivityIndi​​catorView 卡住

标签 iphone ios xcode nsurlconnection uiactivityindicatorview

我有这个函数,它调用一个函数来检查 CMS 的信息。但 UIActivityIndi​​catorView 卡住直到检查完成。不知道为什么。

编辑:有趣的是,我注释掉了 performselector。 UIActivityIndi​​catorView 仍然卡住。直到我点击后退按钮然后它开始旋转....

我正在使用 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 - UIActivityIndi​​catorView 卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9515815/

相关文章:

iphone - 如何从YouTube网址获取缩略图?

ios - 如何使用 UIButton 为单元格设置动画?

ios - 关闭 SwiftUI 中的按钮突出显示

swift - AVPlayerViewController 视频适用于 iOS 11、12,但不适用于 iPhone 11 的 iOS 13

iphone - 在 CIFilter : getting empty image 中使用来自 CIColor 的 CIImage

ios - 在 MPMoviePlayerController 中播放视频时出现 _itemFailedToPlayToEnd 错误

ios - 当用户返回 View Controller 时重新加载 Collection View 数据

iphone - 如何在全屏 OpenGL ES 应用程序上显示 iPhone/iPad 键盘

ios - 尝试在 Swift 中使用警报操作切换到另一个 View Controller

ios - Swift:如何将其他文件导入您的应用程序