首页 文章

Unwind Segue iOS回归1太多VC

提问于
浏览
11

我有一个3视图控制器导航,其中A呈现模态控制器B,它通过segue呈现模态控制器C. C有一个放松的回到B.它还有一个放松回到A.当我为C展开动作放松到B时,它展开然后然后弹出B然后回到A.这不是我想要的,我想要在这种情况下,它留在B.下面是VC C使用的segues .

unwind segues from VC C

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;
    }
}

VC B在.m文件中展开

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

    [self.collectionView scrollToItemAtIndexPath:self.colletionCount atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
}

VC在.m文件中展开

-(IBAction)prepareForUnwind:(UIStoryboardSegue *)segue {
}

2 回答

  • 3

    当从C转到B时,don 't use an unwind segue just have C call dismissViewController. If you'重新致力于使用展开segues,看here具体部分授权如何解开Segue确定其目标视图控制器

  • 2

    我猜你把unwind-segue的标识符与unwind-segue的Action方法混淆了 .

    如果使用“prepareForUnwind”操作构建unwind-segue,然后将此unwind-segue的标识符更改为“unwindCancel” . 问题就会出现 .

    只需确保unwind-segue的标识符与其操作方法匹配 .

相关问题