[viewcontroller保留]:关闭viewcontroller后,发送消息到已释放实例的错误

时间:2018-06-26 09:49:49

标签: objective-c uiviewcontroller uicollectionview apple-tv avplayerviewcontroller

我的应用程序在collectionview中的选择项之后显示viewcontroller(detailsview):

[self presentViewController:detailView animated:YES completion:^{


                }];

从新的视图控制器中启动avplayer,然后关闭播放器,然后关闭(detailsview)viewcontroller并返回主视图控制器。这里的应用程序崩溃了,并显示[detailsviewController keep]错误:发送到已释放实例的消息。这是我在Apple TV中执行的操作。使用菜单操作关闭控制器。

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{ 

 if([assetType isEqualToString:@“MOV”] ||[assetType isEqualToString:@"PRG”] )
            {
                    // Asset landing page

                    NSMutableArray *assets=[[NSMutableArray alloc]initWithObjects:@"ViewAll",nil];
                    [assets addObjectsFromArray:self->allAssetsArray];
                    NSDictionary *SelectedAsset=[self->allAssetsArray objectAtIndex:indexPath.row];
                    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

                    DetailsViewController  *detailView =(DetailsViewController*)[storyboard instantiateViewControllerWithIdentifier:@"DetailsViewController"];

                    OnDemandAssetModel * assetModel=[[OnDemandAssetModel alloc]init];
                    assetModel.identifier=[SelectedAsset objectForKey:@"id"];
                    assetModel.assetCategory=@"";//[category objectForKey:@"name"];
                    assetModel.assetId=[SelectedAsset objectForKey:@"assetId"];
                    assetModel.assetName=[SelectedAsset objectForKey:@"movieName"];
                    assetModel.assetDuration=[SelectedAsset objectForKey:@"runningTime"];
                    assetModel.assetGenre=[SelectedAsset objectForKey:@"genre"];
                    assetModel.assetCategoryType=@"SVoD";
                    assetModel.assetDirector=[SelectedAsset objectForKey:@"director"];
                    assetModel.assetActors=[SelectedAsset objectForKey:@"cast"];
                    assetModel.assetCC=[SelectedAsset objectForKey:@""];

                    assetModel.assetAvailableUntil=[SelectedAsset objectForKey:@"availableUntil"];
                    assetModel.assetRating=[SelectedAsset objectForKey:@"rating"];
                    assetModel.assetPosterPath=[SelectedAsset objectForKey:@"movieImage"];
                    assetModel.assetContentType=[SelectedAsset objectForKey:@"movieType"];
                    assetModel.assetDescription=[SelectedAsset objectForKey:@"description"];
                    assetModel.assetReleasedYear=[SelectedAsset objectForKey:@"releasedYear"];
                    assetModel.subscriptionStatus=[SelectedAsset objectForKey:@"subscription"];

                    detailView.assetModel=assetModel;
                    detailView.selectedAssetID=assetModel.assetId;
                    detailView.selectedIndex=[NSIndexPath indexPathForRow:indexPath.row+1 inSection:0];
                    detailView.identifier=assetModel.identifier;

                    [self showViewController:detailView sender:nil];

                  //  [self presentViewController:detailView animated:YES completion:^{


                   // }];
            }


}

1 个答案:

答案 0 :(得分:0)

您可以通过将detailView保存到实例变量来处理崩溃。现在,它只是一个局部变量,因此在不再使用时将被释放。

在您的@property (strong, nonatomic) DetailsViewController *detailsView;中添加@interface,并在您发布的代码中将detailsView上的分配更改为:

self.detailView = (DetailsViewController*)[storyboard instantiateViewControllerWithIdentifier:@"DetailsViewController"];