View disappears when going back into app then tabs go too
Hi,
First post on the forums but been on here a while. I'm writing my first App and coming pretty near to completion now but got a fairly big bug that can't solve so far.
SDK/iPhone details: XCode 3.2, iOS 4.2 SDK, iPhone 3GS 16GB with iOS 4.33 installed. This bug also happened when I had 4.0 installed on the phone. I can't repeat at the moment in the iPhone Simulator.
Structure wise my app has:
- AppDelegate application function loads up a UITabBarController with two tabs in - each displaying a UIViewController when clicked. AppDelegate also has a member UINavigationController
- The first tab has a UITableViewController in showing my apps "User list" along with the delegate's NavigationController showing at the top
- When you tap on a user, a "UserDetail" UIViewController is pushed on to the NavController.
- The UserDetail view has a UITabBar at the bottom with 6 UITabBarItems in. Tapping on each one will add a different subview - each being a UIViewController. Also up the top is a right-navbarbutton that pushes another UIViewController onto the NavController (so essentially 3 levels down now)
So essentially, it's a 2 tabs on the first screen and then 6 tabs on the next screen level down.
The problem I'm having is that if click the iPhone's home button and leave the app, then go back to the app after a while - when I tap on a user on the first screen, the 6-tab bar is shown at the bottom but the view above isn't displayed - its blank. Then if I tap the right-navbar-button at the top and go to the third level down and then back again - the view has now appeared but my tabs (the 6-tabs) have gone and never come back until I shut the app down and go back in.
Has anyone ever seen this kind of thing before and know where I should look or what more information I could provide to help get an answer?
Hi... I have a bit more info... I now know this is happening after a memory warning to my app and so have now managed to repeat in the simulator with the hardware->simulate memory warning option (I didn't know it was there until now)...
So, now I'm trying to debug through the ViewController that's giving me the problem but still not getting very far, so I thought I'd post the code below (sanitised so its not obvious what I'm writing) of the particular ViewController...
I'm aware I'm currently not doing anything in didReceiveMemoryWarning or viewDidUnload but I'm not quite sure what I need to do for these - any pointers based on the rest of the ViewController would be great...
Hi!!! I saw your code and I have one dubts or two.
OneController is the view that content de tabbarButtons? And when you change view do [self.selectedViewController.view removeFromSuperview] you remove one controller and put the new view? I dont understand this part and if you have 5 or 6 SUBViews.
not exactly sure what problem you are having, but any time i am getting weird behavior like that, I comment out all the [release] lines of code and try running it again. this might help you isolate the problem. if you are releasing something at the wrong time, you app may behave very badly.
You can also force your app to always start at the first screen by checking the "Application does not run in backgr" flag in your info.plist file.
Thanks to those who replied. Rich - I did take your "app does not run in background" route to start with today but then had a brainwave as to what it might be doing and found a solution.
I opened the xib of the first tab view and it hadn't got a bottom bar set to be a tab-bar (so it was covering the tabs when going back into the app) so I set that and then on first draw it appeared to high. So I moved the first subview add from the initWithNibName down to inside the viewDidLoad instead and wrapped it in a nil check on self.selectedViewController - I also had to force the frame of this first subView add to stop it appearing too high:
I then added the following line to the didReceiveMemoryWarning in this ViewController so that I knew the subView had been automatically removed and I'd have to add it again - as that was why it was appearing blank when re-opening the app:
Code:
self.selectedViewController = nil;
Seems to have finally solved the problem... now onto the last steps to release the app at last...