ViewWillAppear, viewDidLoad are lunching twice when app loads
I've been struggeling with this problem for quite some time.
I start the app and the app itself lunches viewWillAppear, viewDidLoad twice and that creates me two views one above the other. So when I click my login button, the same button creates two session ids cos two views are one above the other.
Basically my app is with navigationController and I set the navigationController with the first viewController there. In this viewController I check if there is an existing session ID, if there is no existing session id, it pushes the login View, if there is existing session id it calls another class where creates the URL asynchronius request for populating the table with data.
But somehow, if I don't have a session id the viewDidLoad, viewWill appear are executed twice before the loginView is displayed.
Can somebody tell why this happens and how to solve it?
Are you doing the same thing in both methods? Because if you are, there's your problem. viewDidLoad is for some last minute GUI additions/modifications. viewWillAppear: is for refreshing data, example: refresh a UITableView here.
I think all the problems I have come from the asynchronous request I call from viewWillAppear.
Basically in ViewWillAppear I call a different class that creates a URLRequest and sends that request via URLConnection and that URLConnection starts with executing the delegates. But since is asynchronous request it goes back to the class caller (where I have viewWillAppear) and starts again executing the same function and creates another asynchronous request . In a meantime connectionDidFinishLoading: gives me back the information of the first connection with request and loads the loginView since the user does not exists. Later the second connection is done and loads the second login-view above the existing one. In that way I have same view one above the other.
So how can I make an activity indicator to run in my class caller until all the delegates methods from the URLConnection are done for the first request and make sure no other request is created?
Anyway viewDidLoad still executes twice.
Other then that when I check if session ID exists in NSUserDefaults in ViewWillAppear the viewWillAppear still loads twice and ViewDidLoad executes twice.
Any ideas on this?
Anyway in viewDidLoad and viewWillApear I am performing completely different things.
Describing the problem in English is not going to result in a solution for you. The problem is in your code, or possibly in a XIB, not in your English. Either way, you have shown neither of these things, and until you do, your problem will not be solvable by anyone here.
Describing the problem in English is not going to result in a solution for you. The problem is in your code, or possibly in a XIB, not in your English. Either way, you have shown neither of these things, and until you do, your problem will not be solvable by anyone here.
@BrainSlick: ok I'll take this suggestion for next time, but my code is calling one thing from another and many things depend on another, so basically I would need to post the whole app code.
Anyways I found the solution, why the ViewWillAppear was called twice. The problem was that in the appDelegate, I have a navigationController where I pushed the RootViewController on it, but once you have Navigation Based Application as a project type, the Xcode creates the RootViewController for you and the navigationController in the appDelegate and it pushes the RootViewController on the navigationController. The only thing was that I didn't see, in code, when did the appDelegate pushed RootViewController to the navigationController, cos it happens somewhere in the background but was not written in the appDelegate class.
So by me pushing it again it made it call it once again.
That is why I don't like IB, cos you don't know what is going on in behind and you have less control.
@BrainSlick: ok I'll take this suggestion for next time, but my code is calling one thing from another and many things depend on another, so basically I would need to post the whole app code.
For something like this, if that is true, then you are doing something really wrong.
Quote:
Originally Posted by Lily.P
That is why I don't like IB, cos you don't know what is going on in behind and you have less control.
Not at all. Just because you don't understand it doesn't mean that there is anything going on behind the scenes. There really isn't anything going on behind the scenes. It creates objects and makes connections. That's it. Everything it does is inspect-able. Are there things you need to learn? Sure. But that doesn't mean it is doing black magic.