简体   繁体   中英

Exit views when switching tabs

The Problem

I am trying to use CoreData in my iOS app for persistence. Everything seems to be working well, except for one thing. In some rare cases, I have two view controllers open at the same time that are both accessing the managed object context. The reason for this is that they are both child views of a tab bar controller (and the tab bar controller does not fully exit views when you switch tabs).

What I'm Looking for

I am looking for a way to make the view exit when I switch to a different tab.

This should be a comment but I've not enough reputation.

If you have to-many relationships it could be an approach to use .returnsObjectsAsFaults = false on your fetchrequests.

If your views are doing work while not visible it might be an approach to let your views stop any work by instrumenting viewWillDisappear . This is just to reduce the energy consumption of your app. IMHO that has nothing to do with your issue accessing faults.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM