RestKit 映射在后台释放?
我的应用程序(iPad,iOS 5)中有以下结构:
UIView1 --> UIView2(呈现模式)。
我有一个处理 REST 服务的自定义类。这个类处理所有需要的映射、路由等。 UIView1中有一个对象使用这个类。
从 UIView1 中,我呈现了 UIView2(模态),其中包含 UIWebView,显示一些 HTML 内容和一些 PDF 文档(取决于用户在 UIView1 中选择的内容)。
有时,当用户位于 UIView2 中时,UIView1 似乎在后台被释放。
如果用户现在关闭 UIView2 以返回 UIView1,则应用程序会崩溃。该错误是一种“RestKit 映射...存在”。
在我看来, UIView1 已被释放,现在正在后台构建,但 RestKit 对象仍然存在。 RestKit 是一个共享对象(单例)。
运行这个程序的正确方法是什么?
I have the following structure in my app (iPad, iOS 5):
UIView1
--> UIView2 (presented modal).
I have a custom class dealing with a REST Service. This Class handles all the mapping, routing, etc. needed. There is an object in UIView1 using this class.
From UIView1 i present the UIView2 (modal) which has a UIWebView included, showing some HTML Content and some PDF Documents (depending what was chosen in UIView1 by the User).
Sometimes it looks like UIView1 get'S deallocated in background while the user is in UIView2.
If the User now closes UIView2 to return to UIView1, the app crashes. The Error is kind of "RestKit Mapping for ... exists".
It looks to me, that UIView1 was deallocated, and now is build up in background, but the RestKit object still lives. RestKit is a Shared Object (Singleton).
What is the correct way to get this runnning?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
viewDidLoad 不是设置 RestKit 映射的好地方 - 该方法可能在控制器的生命周期内被多次调用。
初始化 RestKit 并设置所有映射的一个好(且安全)位置是 AppDelegate 中的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
。这样您就可以确保设置过程仅完成一次,并且在发送任何潜在请求之前完成。The
viewDidLoad
is not a good place to set up RestKit mappings - this method may be called multiple times within a lifetime of the controller.A good (and safe) place to initialize RestKit and set up all the mappings is
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
in your AppDelegate. This way you can be sure the set up process is done just once and before any potential request may be sent.