Xcode:故事板并在每个控制器中保留数据

发布于 2024-12-28 08:16:58 字数 192 浏览 2 评论 0原文

正如你可以猜到的,我是一名新程序员,但我很难得到一个简单的东西! 我正在制作一个带有多个视图控制器的应用程序。每个控制器都有文本字段和 UIsegmentedControl 项。当我从一个视图控制器移动到另一个视图控制器时(如果重要的话,使用模态转换),前一个视图控制器的内容(文本字段条目和分段控制选项)将重置为其原始状态。我怎样才能让他们保持以前的状态? 提前致谢。

As you can guess i am a new programmer and i have trouble getting a simple thing!
I am making an app with multiple view controllers. Each controller have textfields and UIsegmentedControl items. When i am moving from one view controller to the other (uding modal trantition if that matters), the contents of the previous one (textfield entries and segmented control option) reset to their original state. How can i make them keep their previous state?
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

划一舟意中人 2025-01-04 08:16:58
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    bViewController *deneme = [segue destinationViewController];
    [deneme setPassedValue:label.text];
}

我希望这段代码能够解决您的问题。它保存其中任何内容的标签。并且您需要向其他类添加更多代码。

如果这段代码对您有帮助,请告诉我,我可以给您完整的代码。

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    bViewController *deneme = [segue destinationViewController];
    [deneme setPassedValue:label.text];
}

This piece of code will solve your problem, I hope. It saves the label of whatever is inside of it. And you need to add some more code to other classes.

If this code helps you tell me and I can give you the whole code.

时光瘦了 2025-01-04 08:16:58

要保存应用程序状态,您可以使用模型类,遵循推荐的 MVC(模型-视图-控制器)范例。
更多信息请参见:重新加载时保留视图状态

作为替代方案 您可以使用 viewWillDisappear: 事件保存视图状态,然后在 viewWillAppear: 事件上恢复它。

viewWillDisappear: 事件在视图即将消失之前触发,而 viewWillAppear: 在视图置于前台之前触发,非常适合对视图进行任何更改用户界面。

这些事件可能已经在您的视图控制器中为您声明了,但如果它们没有在此处检查原型:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

To save the application state you can use a model class, following the recommended MVC (model-view-controller) paradigm.
More information here: Retain view state upon reloading

As an alternative you could use the viewWillDisappear: event to save your view state, and then restore it on the viewWillAppear: event.

The viewWillDisappear: event is fired right before the view is going to disappear, and viewWillAppear: is fired before the view is put on the foreground, being ideal to make any changes to the UI.

These events might have already been declared for you in your view controller, but in case they're not check the prototypes here: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

野稚 2025-01-04 08:16:58

您还可以使用导航控制器从一个视图移动到另一个视图。
这样,您将把新视图推到前一个视图之上,并且当您返回时,前一个视图仍保持其状态。
有关 Storyboard 和 UINavigationController 的更多信息,请参阅本教程:
http://www.raywenderlich.com/5138/beginning -storyboards-in-ios-5-part-1

You can also use a navigation controller to move from one view to another.
This way, you will push your new view on top of the previous one, and when you go back, the previous view has kept its state.
see this tutorial for more information on storyboard and UINavigationController :
http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文