views:

333

answers:

1

Hi, can someone provide a little guidance on the best way to handle iPhone UI and processing while parsing a SOAP message? Here is the context:

  • I have an app that allows a user to select a car (from a list of cars) they are interested in viewing.
  • When they pick a car, I push a carDetails viewcontroller that shows the car detail categories. When I initialize carDetails, I alloc/execute another class called getCarData that contains SOAP and XMLParser methods that retrieve and load all the car details from a web service.
  • Currently, the getCarData class returns control back to carDetails before it has completed it's processing (I believe due to the asynchronous nature of the XMLParser)
  • But I need data from getCarData to be loaded before I allow the user to select any drill-down category information in carDetails (i.e. Interior, Engine, etc.)

My questions are;

  • What is the best way to handle the wait process until the data is loaded?
  • I have seen some forum questions on firing off separate threads so I don't tie up the UI, but I actually do want the user to wait (if necessary) until the data is loaded. So should I create another thread? Should I just simply display a progress window that hides the main window until data is loaded?
  • What is the best way to check and see if the data has finished loading and if not, display the activity/progress view? In other words, should I handle it in the carDetails, getCarData, or maybe the AppDelegate?

Sorry for the multiple questions and (probably) noob problems, but I can't seem to find many discussions or code examples that I can use.

Thanks in advance - Mike

+1  A: 

The typical protocol used by Apple in this situation is to define a method to be called when the processing/loading is done. The method could be called something like this:

-(void)carDetailsDidFinishLoading

You can wait for this method to be called before allowing the user to select things in your interface. Keep everything disabled until this fires.

Since you're essentially freezing your interface, you will probably want to display a loading symbol, UIActivityIndicator, to let the user know your app hasn't just frozen.

Dan Lorenc
Thanks Dan, I definitely would use an activity indicator, but in which class would you suggest putting the objects and methods (the viewController/carDetails or XMLParser/getCarData) and what would you check to make sure the data has loaded. I suppose I could check the array I am loading if that makes sense, or maybe the parser callbacks. Thanks again for taking the time. - Mike
I would keep the UI disabled (disabling all the buttons) until the carDetailsDidFinishLoading method gets called. Use the -parserDidEndDocument method of XMLParser to know when the processing is finished.
Dan Lorenc