I have a view which is pushed onto the UINavigationController stack from another UITableView. My view loads in any cached content and then proceeds to connect to a server to check for newer content.
The trouble is, the user may click the ‘back’ arrow button in the UINavigationBar and when the delegate is fired back the app crashes. I see two ways of approaching this:
- Cancel + set any delegates to nil
- Remove the back button until activity has completed/failed (may be annoying)
Unfortunately, the framework I’m using (RestKit) seems to still crash when I set the RKObjectLoader delegate to nil.
Any clues or best practice about this?
There’s a third option – move the view off screen but don’t release it – the operation will succeed and then you can free the memory.
Option 1 would be the right way to do it – you don’t want to be doing things for no reason. Have you tried intercepting the back button and retaining the view. Cancel the operation but don’t set the delegate to nil. You should get some sort of error message back from restKit to your delegate – when you get this you can release yourself. Meanwhile, the view has been removed off the screen by UIKit so the user has no idea this is happening.
Failing all that not working, option 2 would work (but would suck).
Can you post the stack trace of the crash – maybe we can just fix RestKit ?