CoreData 应用程序中的 popToViewController

发布于 2024-12-03 00:06:06 字数 761 浏览 4 评论 0原文

我有一个 CoreData 应用程序,其中包含 MainView 和 UITableViewController,其中包含列表中的所有项目。我想要完成的是添加自定义后退按钮并使用 popToViewController:animated: 访问设置。当我尝试使用此方法时,应用程序崩溃了。经过大量阅读后,我意识到推送和弹出使用 NSArray 堆栈作为视图控制器。例如,rootView 是视图 0,当您使用 pushToViewController:animated: 时,它会添加到另一个视图 1 等中。这一切都是有道理的。我了解到的是,您无法弹出到根视图之后未加载到堆栈中的视图。我的目标是弹出设置视图。当我更改 AppDelegate.m 中的代码以使 SettingsViewController 成为 rootViewController 时,UITableViewController 不再起作用,它无法告诉我实体“enityName”无法初始化。有什么方法可以让应用程序的 CoreData 部分正常运行并仍然弹出设置?我曾想过使用模态视图,但它破坏了应用程序的风格。

这对我来说很难解释,如果你不明白其中的任何部分,请告诉我。 感谢您的帮助。

更新:我在 UINavigationBar 文档中读到,您可以使用 - (void)setItems:(NSArray *)itemsAnimated:(BOOL)animated ,从而允许您手动设置推送和弹出视图控制器的数组。我只是不知道该怎么做。我已经浏览了苹果的drillDown示例代码,但它没有我正在寻找的功能。

I have a CoreData app with the MainView the UITableViewController which houses all of the items in the list. What i'm trying to accomplish is adding a custom back button and using the popToViewController:animated: to access the settings. When I try to use this method the app crashes. After doing extensive reading I realized that push and pop use an NSArray stack for view controllers. For example, the rootView is view 0, when you use pushToViewController:animated: it added in another view, 1 and so forth. That all made sense. What I learned was you can't pop to a view which is not loaded into the stack after the root view. My objective here is to pop to the settings view. When I change the code around in the AppDelegate.m to make the SettingsViewController the rootViewController, the UITableViewController no longer functions, it fails telling me the entity "enityName" can't be initialized. Is there any way to still have the CoreData part of the app function correctly and still pop to the settings? I have thought of using a modal view but it ruins the style of the app.

This was quite hard for me to explain, if you didn't understand any part of it, let me know.
Thanks for your help.

Update: I read in the UINavigationBar documentation that you can use - (void)setItems:(NSArray *)items animated:(BOOL)animated thus allowing you to manually set the array of pushing and popping view controllers. I just can't figure out how to do that. I've gone through apples drillDown sample code, but it didn't have the functionality I was looking for.

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

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

发布评论

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

评论(1

陌伤ぢ 2024-12-10 00:06:06

也许您误解了 Apple 的导航控制器习惯用法。它旨在深入查看视图的层次结构,并轻松直观地前后移动。

在此层次结构之外的视图(似乎您的设置视图属于此类别)确实应该以模态方式呈现。在 iPad 上,您甚至可以使用漂亮且方便的 UIPopOverController

当然,如果您想保持自己的外观和感觉(导致用户感到困惑的危险),您可以修改过渡动画。您可以使用 Apple 自己的、因此预先批准的 UIViewControllerUIModalTransitionStyle 属性。

或者您可以尝试到目前为止所做的事情并摆弄视图层次结构。也许您可以简单地通过顺序使用视图控制器而不是在中间跳过控制器来消除错误。 就足够了。

[self.navigationController pushViewController:controller animated:YES];

在这种情况下,使用and

[self.navigationController popViewControllerAnimated:YES];

而不是更容易出错的版本 pushToViewControllerpopToViewController

Perhaps you are misunderstanding Apple's navigation controller idiom. It is meant for drilling down a hierarchical structure of views and move back and forward easily and intuitively.

A view that is outside this hierarchy (it seems your Settings View belongs to this category) should really be presented modally. On the iPad, you can even use the pretty and convenient UIPopOverControllers.

Of course, if you want to keep your own look and feel (incurring the danger of confusing your users), you could fiddle with the transition animation. You could use Apple's own and thus pre-approved UIModalTransitionStyle property of UIViewControllers.

Or you could try what you did up to now and fiddle with the view hierarchy. Maybe you can eliminate your errors simply by using the view controllers sequentially and not jumping around skipping controllers in between. In this case it should be enough to use

[self.navigationController pushViewController:controller animated:YES];

and

[self.navigationController popViewControllerAnimated:YES];

rather than the more error prone versions pushToViewController and popToViewController.

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