获取远程 plist 文件,在 UITableView 中使用
我已经成功创建了一个应用程序,它从捆绑的 .plist 文件中读取内容并在 UITableView 中显示内容。我想将该 plist 移动到外部站点,因为它经常更新。更好的是,我希望用 PHP 生成它。我已经让服务器端工作了,但是 Objective C 让我头疼...
我的代码过去是这样读的:
NSString *myfile = [[NSBundle mainBundle] pathForResource:@"notices" ofType:@"plist"];
根据各种谷歌搜索,我的代码现在应该看起来像这样:
NSString *myfile = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"http://localhost/plistgen1.php"]];
显然这是行不通的,将 NSString 与 NSDictionary 混合,但我尝试过(但失败了)让它正常工作。有没有人有解决方案,或者有不同的方法来解决这个问题?我使用的数据位于 mysql 服务器上,plistgen1.php 只是“填充 plist 文件中的空白”并回显它......
我可能都弄错了,不要开枪打我:)
I have successfully created an app that reads from a bundled .plist file and displays the contents in a UITableView. I would like to move that plist to an external site, as it is updated frequently. even better, I would love to have it generated with PHP. I have got the server side working, but the Objective C is giving me a headache...
My code used to read like this:
NSString *myfile = [[NSBundle mainBundle] pathForResource:@"notices" ofType:@"plist"];
according to various google searches, my code should now look something like this:
NSString *myfile = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"http://localhost/plistgen1.php"]];
Obviously this is not going to work, mixing NSString with NSDictionary, but I have tried (and failed) to get it to work properly. does anyone have a solution, or a different way to approach the problem? The data I am using is on a mysql server, and the plistgen1.php just "fills in the blanks" in the plist file and echoes it out...
I may have got this all wrong, don't shoot me :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一种情况(“我的代码过去是这样读的”)为您提供了捆绑的 plist 文件的本地文件系统路径,并将其保存到变量
myfile
中。在第二种情况下,您从服务器下载 plist 文件的内容并从中创建字典。在将文件路径分配给
myfile
后,您可能有一些代码将该文件的内容读取到NSDictionary
中。您需要用第二个示例替换对myfile
的赋值和该语句。这样的内容替换:
所以你可以用
The first case ("My code used to read like this") gives you the local filesystem path to the bundled plist file and saves it to the variable
myfile
. In the second case you're downloading the plist file's contents from the server and creating a dictionary from that.You probably have some code after the assignment of the file path to
myfile
that reads the contents of that file into anNSDictionary
. You need to replace both the assignment tomyfile
and that statement with the second example.So you'd replace something like this:
With this: