Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-01-2012, 04:40 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2011
Location: Denmark
Posts: 12
Lily.P is on a distinguished road
Default 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?

If you need more info let me know.

Thanks,
Lily
Lily.P is offline   Reply With Quote
Old 02-01-2012, 06:38 AM   #2 (permalink)
[[Brain alloc]init];
 
fhsjaagshs's Avatar
 
Join Date: Aug 2011
Location: New Jersey
Age: 15
Posts: 92
fhsjaagshs is on a distinguished road
Default

Post some code...

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.
fhsjaagshs is offline   Reply With Quote
Old 02-01-2012, 08:00 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2011
Location: Denmark
Posts: 12
Lily.P is on a distinguished road
Default

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.
Lily.P is offline   Reply With Quote
Old 02-01-2012, 08:18 AM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

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.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-03-2012, 06:06 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2011
Location: Denmark
Posts: 12
Lily.P is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
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.
Lily.P is offline   Reply With Quote
Old 02-03-2012, 10:48 AM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Quote:
Originally Posted by Lily.P View Post
@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 View Post
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.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.

Last edited by BrianSlick; 02-03-2012 at 11:07 AM.
BrianSlick is offline   Reply With Quote
Reply

Bookmarks

Tags
ios, iphone, viewcontroller, viewdidload, viewwillappear

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 419
17 members and 402 guests
Atatator, chiataytuday, condor304, dre, FrankWeller, imac74, ipodphone, jeroenkeij, kukat, LunarMoon, MAMN84, n00b, PowerGoofy, QuantumDoja, Retouchable, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,675
Threads: 94,124
Posts: 402,909
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Retouchable
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:02 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0