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 03-30-2010, 10:21 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 6
Chris20ten is on a distinguished road
Default Xml Parsing and UITableView

Hi,

I am totally new to iPhone development and objective-c, so busy banging my head around at the moment.

I have, what I though was going to be a simple task, connect to Web Service, download xml doc, parse and fill a table with the parsed data. I have done loads of tutorials but they all seem to be separate bits, nothing really brings it all together nicely. So far I can connect to, download and parse the xml doc.

I have a view which has a table view inside it, now the problem is that the table view methods: -numberOfSectionsInTable – numberOfRowsInSection etc.. run before the xml has parsed so the array I want to use to fill the table is always empty. How do I parse and get to parserDidendDocument before the table view is loaded? By the way I have tried various methods in the main view .m file i.e. viewWillAppear, loadView, viewDidLoad etc

HELP

Thanks in advance
Chris
Chris20ten is offline   Reply With Quote
Old 03-30-2010, 10:37 AM   #2 (permalink)
Will Work for Food!
 
itzdark's Avatar
 
Join Date: Apr 2009
Posts: 579
itzdark is on a distinguished road
Send a message via AIM to itzdark Send a message via MSN to itzdark
Default

Quote:
Originally Posted by Chris20ten View Post
Hi,

I am totally new to iPhone development and objective-c, so busy banging my head around at the moment.

I have, what I though was going to be a simple task, connect to Web Service, download xml doc, parse and fill a table with the parsed data. I have done loads of tutorials but they all seem to be separate bits, nothing really brings it all together nicely. So far I can connect to, download and parse the xml doc.

I have a view which has a table view inside it, now the problem is that the table view methods: -numberOfSectionsInTable – numberOfRowsInSection etc.. run before the xml has parsed so the array I want to use to fill the table is always empty. How do I parse and get to parserDidendDocument before the table view is loaded? By the way I have tried various methods in the main view .m file i.e. viewWillAppear, loadView, viewDidLoad etc

HELP

Thanks in advance
Chris
in didEndDoc put [tableView reloadData];
__________________

Check out my apps

Developers, check out study buddy. I use it everytime I code. It's great for those late night coding sessions.
Unofficial Ad Hoc Distribution Guide || Join my cooperative ad hoc testing group
iSoothe Promotional Video
Contact Me
itzdark is offline   Reply With Quote
Old 03-30-2010, 11:01 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 6
Chris20ten is on a distinguished road
Default

Hi itzdark,

Tahnks for prompt reply. Just to check a couple of things;

1. Is didEndDoc a method of the view the table is inside? If so the page does not enter this method.

2. If the [tableView reloadData] method should be in parserDidEndDocument then it i have a slight problem as I have included all the parser code inside a seperate class. So the tableview is not available, and I cant pass the table view into the class using a seperate method as the method will be called before the doc has finished parsing, so back to the original problem.

....am I missing something here?

Cheers
Chris

ps.. bear with me
Chris20ten is offline   Reply With Quote
Old 03-30-2010, 11:30 AM   #4 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

I generally put the parser code in another class as well. Better organization IMO.

You still have several options
1. You can post a notification in your didEndDocument method that you would listen for in your table view class. When you receive the notification, call the reloadData method on your UITableView. Google NSNotification if you don't know how to do this.

2. You could pass an instance of your UITableView to the parser class, or have define a property that you can set, etc etc. Then you would have direct access to that UITableView inside your didEndDocument method, so you could call reloadData from there.

3. There are some other options as well, but either of the first 2 should do.
smithdale87 is offline   Reply With Quote
Old 03-31-2010, 01:32 PM   #5 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 6
Chris20ten is on a distinguished road
Default

Hi smithdale87,

Thanks for your reply, I have my tableview working fine now except for one last issue; the cells have duplicate data in them,

I have an array of objects which is created while parsing xml, this array is _sectionsArray, within each one of the objects in _sectionsArray I have another array of objects _rowsArray.

This allows me to set my sections nicely, however when I try to populate the rows, doing this in the cellForRowAtIndexPath method, the cells get duplicated data..

this is how I'm trying to do it:
....
// Configure the cell...
int itemIndex = [indexPath indexAtPosition: [indexPath length] - 1];
WOWAG *wowItem = [_sectionsArray objectAtIndex:itemIndex];
WOWAG *wowCell = [wowItem._wowagitems objectAtIndex:itemIndex];
cell.textLabel.text = wowCell._innerXML;

....how do I loop through each section then each sections' rows?

Cheers
Chris
Chris20ten is offline   Reply With Quote
Old 03-31-2010, 01:50 PM   #6 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 6
Chris20ten is on a distinguished road
Default

Hi,

..cant see the forest for the trees.... I simply had to use [indexPath section] and [indexPath row] to iterate throught the arrays.

All working nicely now,

Thanks for replies...
Chris20ten is offline   Reply With Quote
Old 03-31-2010, 01:59 PM   #7 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

cheers!
smithdale87 is offline   Reply With Quote
Reply

Bookmarks

Tags
table view, xml parsing

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: 317
7 members and 310 guests
checkright, chemistry, heshiming, iAppDeveloper, jbro, kapps11, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,112
Posts: 402,872
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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