简体   繁体   English

iPhone SDK:UITableview动态内容

[英]iPhone SDK: UITableview Dynamic Content

I have a UITableview setup in my iphone app. 我的iPhone应用程序中有一个UITableview设置。 At the moment, each row is populated with items from an NSMutableArray. 目前,每一行都填充了NSMutableArray中的项目。 The array gets data from a mysql database which I have to update myself in order to update the contents of the tableview. 该数组从mysql数据库获取数据,我必须更新自己才能更新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. 我试图通过使其从html表中获取内容并使用它而不是将数据库用作数据源,来使此tableview的填充更加自动和动态。 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. 我可以想到几种将数据从HTML导入NSMutableArray的方法,然后可以将其显示在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. 一种方法是将HTML放入UIWebView,然后使用stringByEvaluatingJavaScriptFromString:方法从HTML表中提取数据。 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. 由于此方法返回的是字符串而不是数组,因此您可能还需要一个JSON库才能将字符串转换为数组。 This would probably be a good approach if you're displaying the HTML anyway, and want to write as little code as possible. 如果您仍然要显示HTML,并且想要编写尽可能少的代码,那么这可能是一个好方法。

If you don't want to display the HTML, then you might prefer to parse it directly using libxml2, which is built into iOS. 如果您不想显示HTML,那么您可能更喜欢直接使用iOS中内置的libxml2对其进行解析。 Then you can use XPath queries to extract the data from the HTML table. 然后,您可以使用XPath查询从HTML表中提取数据。 There's a good article on the Cocoa with Love website that explains how to use libxml2 on iOS. Cocoa with Love网站上有一篇很好的文章,介绍了如何在iOS上使用libxml2。 This approach is probably more efficient, but will require more code. 这种方法可能更有效,但是需要更多代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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