[英]ios swift: return to previous view controller
from a dynamic tableView
"CardSets" I do a segue to a static tableView
"AddCardSet" to enter some data. 从动态
tableView
“ CardSets”中,我对静态tableView
“ AddCardSet”进行输入,以输入一些数据。 After successfull save()
method I want to send the user back to the initial tableView
"CardSets". 成功的
save()
方法之后,我想将用户发送回初始tableView
“ CardSets”。 How can I do that? 我怎样才能做到这一点?
Do I have to set a segue onto the save
button? 我是否需要在
save
按钮上设置segue? Or is there a shorter way? 还是有更短的方法?
You can use popViewControllerAnimated
: 您可以使用
popViewControllerAnimated
:
if let navigationController = self.navigationController
{
navigationController.popViewControllerAnimated(true)
}
the best answer is to create A singltone like this : 最好的答案是像这样创建A singltone:
for example : 例如 :
class Collage { 类Collage {
var classes: [Class] = []
static var collageSharedInsttance : Collage? = nil
static func GetSharedInstance() -> Collage {
if collageSharedInsttance == nil {
collageSharedInsttance = Collage()
}
return collageSharedInsttance!
}
} }
and Access your data from the second controller like this : 并从第二个控制器访问您的数据,如下所示:
var JohnBryceCollage = Collage.GetSharedInstance()
The best option is to use Unwind segue
for this case. 最好的选择是在这种情况下使用
Unwind segue
。 They allow you to jump back through navigation stack. 它们使您可以跳回导航堆栈。 And they are independent of how your controllers are presented - modally or within
UINavigationController
stack. 而且它们独立于控制器的显示方式-模态化或在
UINavigationController
堆栈中。 More of that they allow you to jump through multiple levels back. 更多的是,它们使您可以跳回多个级别。
Please check out Apple's Tech Note and this great answer 请查看Apple的技术说明和这个很棒的答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.