Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何以编程方式从局部视图控制器返回到主视图控制器?_Ios_Iphone_Swift_Swift2_Navigationcontroller - Fatal编程技术网

Ios 如何以编程方式从局部视图控制器返回到主视图控制器?

Ios 如何以编程方式从局部视图控制器返回到主视图控制器?,ios,iphone,swift,swift2,navigationcontroller,Ios,Iphone,Swift,Swift2,Navigationcontroller,我一直无法将数据从详图视图控制器传递到主视图控制器。感兴趣部分的层次结构如下所示 TabBarController -> Profile View Controller --segue--> Navigation Controller -> Detail View Controller 细节视图控制器包含图像的UICollectionView,每个图像都有一个点击手势识别器。我试图做的是点击其中一个图像,将indexPath.row传递给ProfileViewControll

我一直无法将数据从详图视图控制器传递到主视图控制器。感兴趣部分的层次结构如下所示

TabBarController -> Profile View Controller --segue--> Navigation Controller -> Detail View Controller
细节视图控制器包含图像的UICollectionView,每个图像都有一个点击手势识别器。我试图做的是点击其中一个图像,将indexPath.row传递给ProfileViewController,然后以编程方式返回

当我转到细节视图控制器时,已经有一个后退按钮,所以我的想法是:如果用户按下“后退”按钮,什么也不会发生。如果用户按下图像,则“后退”按钮将自动触发,配置文件中的图像将发生更改

到目前为止,我可以点击图像,传递indexPath.row,但我无法返回到上一个视图控制器

我尝试了
navigationController?.popViewControllerAnimated(true)
navigationController?.popToRootViewControllerAnimated(true)
但是这两个都不起作用(我将它们放入手势的点击功能中,导航控制器没有任何变化,点击功能工作正常)

当我打印以下内容时,我得到1
navigationController.viewControllers.count


我唯一能够工作的是
dismissViewControllerAnimated
,但是它从TabBarController转到了之前的另一个视图

请在视图控制器
纵断面图控制器
详细视图控制器
中使用NSIndexPath强属性创建属性。另外,在
prepareforsgue
中从名为
Profile view controller
的视图控制器传递该对象的引用,如下所示:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Make sure your segue name in storyboard is the same as this line
    if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])
    {
        // Get reference to the destination view controller
        Detail_View_Controller *vc = [segue destinationViewController];

        // Pass any objects to the view controller here, like...
        [vc setMyIndexPath:self.object_indexPath];
    }
}
详细说明_View _Controller,当您点击“上一步”按钮时,请通过创建一个iAction更新同一属性中选定的索引,该iAction是从上一个视图控制器传递的

我引用了。

更新

我弄明白了,这与程序无关,正确的答案是使用
navigationController?.popViewControllerAnimated(true)
但是我的视图层次结构是错误的

TabBarController -> Navigation Controller -> Profile View Controller --segue-> Detail View Controller

现在它可以正常工作了

@korat prashant我已经有了一些可以做到这一点的东西,但是我想用一些本地的东西,不用segue就可以回去了。我试过放松赛格,但也没有动作。