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)
但是这两个都不起作用(我将它们放入手势的点击功能中,导航控制器没有任何变化,点击功能工作正常)
当我打印以下内容时,我得到1navigationController.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就可以回去了。我试过放松赛格,但也没有动作。