iOS:返回到上一个视图

iOS:返回到上一个视图,ios,swift,viewcontroller,Ios,Swift,Viewcontroller,在故事板中,我有两种类似的观点: [View1]->[Navigation Controller]->[View2] 要从View1(具有tableview)转到VIEW2,请单击View1上的一行: self.performSegueWithIdentifier("showmyview2", sender:self) 这很有效 现在,我在视图2上有一个按钮,单击该按钮时,我将返回到上一个视图,即视图1 我试过这个: navigationController!.popViewControll

在故事板中,我有两种类似的观点:

[View1]->[Navigation Controller]->[View2]

要从View1(具有tableview)转到VIEW2,请单击View1上的一行:

self.performSegueWithIdentifier("showmyview2", sender:self)
这很有效

现在,我在视图2上有一个按钮,单击该按钮时,我将返回到上一个视图,即视图1

我试过这个:

 navigationController!.popViewControllerAnimated(true)

但这是行不通的。如何返回第一视图?

使用此代码在按钮操作中显示第一视图:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("FirstView") as! TableViewController
self.presentViewController(vc, animated: true, completion: nil)
别忘了给你的第一个视图提供Id

选择您的第一个视图进入故事板,然后单击Identity Inspector,您可以将类似show的故事板ID分配到下图中


如果导航不存在,首先通过故事板向第一个视图1添加导航控制器。(编辑器->嵌入导航控制器)

调用此函数并尝试代替导航popviewcontroller。self.dismise(动画:true,完成:nil);
这将在swift 3中起作用

您的性能检查是pushview控制器还是presentview控制器??miuku>不确定,我在哪里看到?NavigationController是identity inspector中的UINavigationController类。抱歉,我是iOS新手,Swiftyour View1不在navigationcontroller层次结构中,因此您无法调用navigationcontroller上的popViewController返回View1检查此。。。Vinay>那么,我如何将View1引入navigationController层次结构,或者其他任何解决方案?Dharmesh>在故事板中选择View1后,我看不到在Identity或Attribute Inspector中提供ID的方法。SWIFT 3.0语法已像这样更改<代码>自我解除(动画:true,完成:nil)
self.dismissViewControllerAnimated(true, completion: nil);