0 url xcode objective-c plist ios
我有以下代码从资源文件夹加载plist文件并使用它来填充tableview:
NSString *path = [[NSBundle mainBundle] pathForResource:@"AnimeDB" ofType:@"plist"];
NSMutableArray* tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
self.dataList1 = tmpArray;
[tmpArray release];
Run Code Online (Sandbox Code Playgroud)
但我需要从URL加载此.plist文件.我尝试了一些我在网上找到的解决方案,但我无法让它运行起来.有人知道我该怎么做?
也许有一个简单的解决方案,但我开始使用xcode(这是我的第一个应用程序),所以我找不到它.
任何帮助真的很感激!
PS对不起我可能犯的任何错误,我的英语不太好.
我建议考虑使用Json.它允许您将类似结构化数据的plist从网址传递到您的应用.
NSData *dataReturn = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://someUrl.com/test.json"]];
if (dataReturn) {
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:dataReturn options:kNilOptions error:Nil];
Run Code Online (Sandbox Code Playgroud)
如果你想使用你的plist,那么它的代码大致相同:
// This will get the plist into data format
NSData *dataReturn = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://someUrl.com/test.plist"]];
// This will convert data format to array
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:dataReturn]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4015 次 |
| 最近记录: |