开发者

Problems getting an xml feed parsed and loaded into a tableview using delegates

开发者 https://www.devze.com 2023-02-20 19:17 出处:网络
Very new to programming for iOS and Cocoa so please take it easy on me as I try to wrap my brain around the following. I\'m trying to display a tableview populated from an XML feed as the opening scre

Very new to programming for iOS and Cocoa so please take it easy on me as I try to wrap my brain around the following. I'm trying to display a tableview populated from an XML feed as the opening screen of my app. I've tried to consume the XML from inside my AppDelegate using th开发者_运维技巧e ApplicationDidFinishLaunching method (and then making my AppDelegate a delegate for the XML parser which I access using a NSUrlConnection and its delegate methods) but I can't figure out how to take the parsed XML file and pass it to a tableviewcontroller which can then use it as the datasource for a tableview. When I do try, I always get a blank tableview.

I've written the code a few times and nothing seems to work.. I'll post what I have here to show what I've got so far but I'm afraid its mostly vanilla AppDelegate with a few parser methods thrown in.. any pointers in the right direction would be super appreciated.

Thank you in advance!


Hmm, probably a bad idea to do the network call in the AppDelegate. Try to put all that code at the view controller level. Here's a brief structure of what I do (Since it's very similar)

  • View Controller listens to button events
  • Use ASIHTTPRequest to talk to your web service. Handles network really well, you can skip the NSURLConnection stuff.
  • Try to load your data source (an array?) with static values and see if they come up on the table view.
  • Parse the response from ASIHTTPRequest using NSXMLParser, and load the data you want into the static array you were using. More here.
  • Call [tableView reloadData] once you're done and the changes will reflect.


Did you specify a UITableViewDataSource for your table view and implement the two required methods?

tableView:cellForRowAtIndexPath: and tableView:numberOfRowsInSection:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html

When I get blank tables, this is what it is; I've forgotten to specify the data source

0

精彩评论

暂无评论...
验证码 换一张
取 消