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
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
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.
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.
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?