简体   繁体   中英

iPhone SDK: UITableview Dynamic Content

I have a UITableview setup in my iphone app. At the moment, each row is populated with items from an NSMutableArray. The array gets data from a mysql database which I have to update myself in order to update the contents of the tableview.

I'm trying to make the populating of this tableview more automatic and dynamic by getting it to grab content from a html table and using that instead of using the database as a data source. Is this possible and if so, are there any suggested methods?

Also the website that it grabs content from will be different for different views, so I can't define a set of parsing rules for a specific website.

Thanks in advance.

I can think of a couple of ways to get data from HTML into an NSMutableArray that you could then display in a UITableView.

One approach is to get the HTML into a UIWebView and then use the stringByEvaluatingJavaScriptFromString: method to extract the data from the HTML table. Since this method returns a string rather than an array, you'll probably also need a JSON library to convert the string to an array. This would probably be a good approach if you're displaying the HTML anyway, and want to write as little code as possible.

If you don't want to display the HTML, then you might prefer to parse it directly using libxml2, which is built into iOS. Then you can use XPath queries to extract the data from the HTML table. There's a good article on the Cocoa with Love website that explains how to use libxml2 on iOS. This approach is probably more efficient, but will require more code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM