在IOS屏幕锁定后返回时,UI冻结

在IOS屏幕锁定后返回时,UI冻结,ios,iphone,multithreading,uitableview,uiapplicationdelegate,Ios,Iphone,Multithreading,Uitableview,Uiapplicationdelegate,我正在开发一个下载应用程序。我被卡住了,当用户在设备屏幕锁定后返回时,我的UI就被卡住了。所有内容都变为零,无论是UITableview还是NSMutableArray,所有与UI相关的内容都变为零,但我的下载仍在继续。 只有当DevicePhone/iPad获得自动屏幕锁定或用户通过锁定按钮强制屏幕锁定时,才会发生这种情况。如果应用程序通过home按钮进入后台,则一切正常。我想不出可能遗漏了什么。这是我正在使用的代码 - (void)applicationDidBecomeActive:(UI

我正在开发一个下载应用程序。我被卡住了,当用户在设备屏幕锁定后返回时,我的UI就被卡住了。所有内容都变为零,无论是UITableview还是NSMutableArray,所有与UI相关的内容都变为零,但我的下载仍在继续。 只有当DevicePhone/iPad获得自动屏幕锁定或用户通过锁定按钮强制屏幕锁定时,才会发生这种情况。如果应用程序通过home按钮进入后台,则一切正常。我想不出可能遗漏了什么。这是我正在使用的代码

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

    if (isComingFromBackGround == YES)
    {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[AppDelegate storyboardIdentifier] bundle:Nil];
        ViewController *obj = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];

        [obj calledWhenComingFromBackground];
    }

}


-(void)calledWhenComingFromBackground
{
 NSArray *downloadingArray = [[LibraryAPI sharedInstance] getDownloadingVideos];
   if ([downloadingArray count] != 0)
    {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[AppDelegate storyboardIdentifier] bundle:Nil];
        DownloadViewController *obj = [storyboard instantiateViewControllerWithIdentifier:@"DownloadViewController"];

        [obj setIscomingFromBackground:YES];
        [obj notificationsHandler:Nil];
    }
}



-(void)notificationsHandler:(NSNotification *)notification
{
  for (DownloadingVideo *objDV in currentDownloadingArray)
    {
       NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL          URLWithString:tempStr] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];

        [httpClient.operationQueue setMaxConcurrentOperationCount:10];
        AFDownloadRequestOperation *operation = [[AFDownloadRequestOperation alloc]  initWithRequest:request targetPath:targetPath2 shouldResume:YES];
        [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
         {
             NSLog(@"\t -:Success Block CAlled:- ");
             processSuccessBlock(operation, responseObject);
             [self badgedValue];

         } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

             if (operation.isCancelled)
             {
                 NSLog(@"the operation is cancelled...");
             }
             else
             {
                 if(operation.response.statusCode!= 200)
                 {
                     NSLog(@"the Faliour Occurred!!!!!!");
                     processFailureBlock(operation, error);
                 }

             }

             [self badgedValue];

         }];
 [httpClient enqueueHTTPRequestOperation:operation];

        [operation setProgressiveDownloadProgressBlock:^(AFDownloadRequestOperation *operation,NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile) {

            NSString *tempStr = operation.request.URL.absoluteString;
            for (DownloadingVideo *objDownloading in [[[LibraryAPI sharedInstance] getDownloadingVideos] mutableCopy])
            {
                NSDictionary *tempDic = [objDownloading dv_tableRepresentation];

                if ([[tempDic objectForKey:@"Url"] isEqualToString:tempStr])
                {

                    float tempPercentDone = [[tempDic objectForKey:@"ProgressStatus"] floatValue];

                    float percentDone = ((float)totalBytesReadForFile) / totalBytesExpectedToReadForFile;
                    NSString *str = [NSString stringWithFormat:@"%.2f",percentDone];
                    percentDone = [str floatValue];

                    float progressOffset1 = (float)totalBytesReadForFile/1024;
                    float progressOffset2 = (float)totalBytesExpectedToReadForFile/1024;

                    NSString *strProgressStatus;
                    NSString *strProgressLblValue;
                    NSString *strSizeLblValue;
                    NSString *strSize;

                    if (tempPercentDone < percentDone)
                    {
                        strProgressStatus   = [NSString stringWithFormat:@"%0.2f", percentDone];
                        strProgressLblValue = [NSString stringWithFormat:@"%.0f%% Completed", percentDone*100];

                    }
                    else
                    {
                        strProgressStatus   = [NSString stringWithFormat:@"%0.2f", tempPercentDone];
                        strProgressLblValue = [NSString stringWithFormat:@"%.0f%% Completed", tempPercentDone*100];
                    }

                    strSizeLblValue = [NSString stringWithFormat:@"%.2f/%.2f MB",progressOffset1/1024, progressOffset2/1024];

                    strSize  = [NSString stringWithFormat:@"%.2f MB",progressOffset2/1024];

                    NSString *strTitle              = [tempDic objectForKey:@"Title"];
                    NSString *strUrl                = [tempDic objectForKey:@"Url"];
                    NSString *strVideoID            = [tempDic objectForKey:@"VideoID"];
                    NSString *strThumbnail          = [tempDic objectForKey:@"Thumbnail"];
                    NSString *strSmallerThumbnail   = [tempDic objectForKey:@"SmallerThumbnail"];

                    NSString *strDuration           = [tempDic objectForKey:@"Duration"];
                    NSString *strYoutubeValue       = [tempDic objectForKey:@"YoutubeValue"];
                    NSString *strM3u8               = [tempDic objectForKey:@"m3u8"];
                    NSString *strIsDownloadingPaused= @"NO";

                    DownloadingVideo *newObjDownloading = [[DownloadingVideo alloc] initWithTitle:strTitle url:strUrl videoID:strVideoID thumbnail:strThumbnail smallerThumbnail:strSmallerThumbnail size:strSize duration:strDuration youtubeValue:strYoutubeValue m3u8:strM3u8 progressStatus:strProgressStatus progressLblvalue:strProgressLblValue sizeLblValue:strSizeLblValue isDownloadingPaused:strIsDownloadingPaused];

                    int newIndex = [[[LibraryAPI sharedInstance] getDownloadingVideos] indexOfObject:objDownloading];

                    [[LibraryAPI sharedInstance] updateVideoInDownloading:newObjDownloading atIndex:newIndex updateCoredata:NO];

                    DownloadingVideo *tempNewObjDV = [[[LibraryAPI sharedInstance] getDownloadingVideos] objectAtIndex:newIndex];
                    NSDictionary *newDic = [tempNewObjDV dv_tableRepresentation];

                    // Update the corresponding table view cell

                    NSInteger row = newIndex;
                    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
                    UITableViewCell *cell = (UITableViewCell*)[self.tblview cellForRowAtIndexPath:indexPath];

                    [self setupCell:cell withAttributes:newDic];

                    break;
                }
            }            
        }];

    }

    [self badgedValue];
    [self.tblview reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];

}
编辑

此错误发生在cellForRowAtIndexPath。这是密码

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyIdentifier;
    UITableViewCell * cell;

    if (indexPath.section == 0)
    {
        MyIdentifier  = @"Cell";
        cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

        if (cell == nil)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
        }

        DownloadingVideo *objDV = [[[LibraryAPI sharedInstance] getDownloadingVideos] objectAtIndex:indexPath.row];

        NSDictionary *dic = [objDV dv_tableRepresentation];
        [self setupCell:cell withAttributes:dic];
    }
    return cell;
}

请帮助我,因为我的想法已经没有了。

添加一个捕获所有异常断点,然后告诉我们该异常发生的位置。hi@意思是,我在添加所有异常断点后尝试了它,但没有成功。仅收到上述错误报告。您的应用程序在该断点上的何处停止?这就是我所问的。@意思是当我滚动时,cellForRowAtIndexPath中的内容。起初什么也没发生。只是冻结了用户界面,没有例外。但当我在滚动时,下载完成后,CellForRowatineXpath出现异常。那么为什么不显示该代码呢?
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyIdentifier;
    UITableViewCell * cell;

    if (indexPath.section == 0)
    {
        MyIdentifier  = @"Cell";
        cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

        if (cell == nil)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
        }

        DownloadingVideo *objDV = [[[LibraryAPI sharedInstance] getDownloadingVideos] objectAtIndex:indexPath.row];

        NSDictionary *dic = [objDV dv_tableRepresentation];
        [self setupCell:cell withAttributes:dic];
    }
    return cell;
}