在视图控制器之间切换时数据消失 [英] Data disappears when switching between view controllers

查看:29
本文介绍了在视图控制器之间切换时数据消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用故事板编写 iPhone 应用程序作为初始模型.我现在的问题是切换视图控制器.

I am writing an iPhone application using the storyboards for an initial mockup. The problem I have right now is switching view controllers.

我有一个表视图控制器和另一个视图控制器.我想要做的就是使用后退按钮返回原始屏幕,我可以这样做,只是数据消失了.我拥有的故事板如下所示.

I have a table view controller and another view controller. All I want to do is use a back button to go back to the original screen, and I can do that, except the data disappears. The storyboard that I have is shown below.

我有返回按钮返回到原始导航控制器.我也让它回到 Card 视图控制器.

I have the Back button going back to the original navigation controller. I have also had it going back to the Card view controller.

我对一些示例单元格进行了硬编码,以查看事物的外观,当我运行模拟时,它们显示得很好.但是,当我单击后退按钮时,它会返回到所有卡片"屏幕,并且原来的单元格现在消失了.

I have hard coded some example cells to just see how things look and they show up just fine when I run the simulation. When I click the back button though, it goes back to the All Cards screen and the cells that were there are now gone.

如果我需要发布一些代码,只需询问哪些部分会有所帮助,我已经通过故事板完成了所有这些.

If I need to post some code just ask for what part would be helpful, I have done all of this through storyboards though.

我敢肯定这是我做过的蠢事,任何指向正确方向的点都将不胜感激.

I'm sure it's something stupid I've done, any point in the right direction would be greatly appreciated.

推荐答案

基本上:你推到了你应该弹出的地方.

Basically: you pushed where you should have popped.

您在 Storyboard 上看到的内容尚不存在.通过在运行时到视图控制器的 segue-waying,它被实例化.

What you are seeing on the Storyboard does not exist yet. By segue-waying during runtime to a view controller it gets instantiated.

当您在运行时从 Add Card 视图控制器返回"到 Card 视图控制器 时,发生了以下情况:而不是弹出导航堆栈一直回到您已经拥有的卡片视图控制器,您只需实例化一个新的卡片视图控制器并将其推送到导航堆栈上.您可以通过多次点击后退按钮返回到原始卡片视图控制器来验证这一点.

When you segue-wayed during runtime from the Add Card view controller "back" to the Card View Controller - here is what happened: instead of popping the navigation stack all the way back to the Card View Controller you already had, you just instantiated a new Card View Controller and pushed it onto the navigation stack. You could verify that by going all the way back to the original Card View Controller by tapping the back button several times.

为了完成您的任务,您可以做的是:在代码中使用 IBAction 而不是使用 Storyboard 作为您的后退按钮:

What you could do to accomplish your task is this: Instead of using the Storyboard for your back button use an IBAction in code:

- (IBAction)popToRoot:(id)sender {

    [self.navigationController popToRootViewControllerAnimated:YES];

}

这篇关于在视图控制器之间切换时数据消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆