Unwind Segue iOS回归1太多VC

noo*_*obs 11 uiviewcontroller ios unwind-segue

我有一个3视图控制器导航,其中A呈现模态控制器B,它通过segue呈现模态控制器C. C有一个展开SEGUE回到B.它也有一个开卷回答:当我执行对C放松到B,它解开行动,但随后弹出B和追溯到答:这不是我想要的,我想在这种情况下,它留在B.下面是VC C使用的segues.

从VC C中解除segues

unwindCancel用于当用户点击collectionViewCell并返回VC B. prepareForUnwind只是VC A的标准"取消"按钮.

下面是在VC C中调用unwind的didSelectItem的代码.下面是VC C中的prepareForSegue.

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
[self performSegueWithIdentifier:@"unwindCancel" sender:self];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"unwindCancel"]) {
        GalleryDetailViewController *detailVC = segue.destinationViewController;
        detailVC.colletionCount = self.indexPathToPass;
    }
}
Run Code Online (Sandbox Code Playgroud)

VC B在.m文件中展开

-(IBAction)unwindCancel:(UIStoryboardSegue *)segue{

    [self.collectionView scrollToItemAtIndexPath:self.colletionCount atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

VC在.m文件中展开

-(IBAction)prepareForUnwind:(UIStoryboardSegue *)segue {
}
Run Code Online (Sandbox Code Playgroud)

bey*_*ulf 3

从 C 到 B 时,不要使用展开转场,只需让 C 调用 DismissViewController。如果您致力于使用展开转场,请具体查看此处标题为“展开转场如何确定其目标视图控制器”的部分