首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Plist加载Plist的URL

从Plist加载Plist的URL
EN

Stack Overflow用户
提问于 2013-03-27 20:49:20
回答 2查看 127关注 0票数 0

我尝试使用initWithContentsOfURL:从其他plist文件加载plist文件

我解释说,我在我的主机中有一个使用plist文件的表视图,使用以下方法:

代码语言:javascript
复制
NSMutableArray *genres = [[NSMutableArray alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.myurl.com/file.plist"]];
    self.loadGenres = genres;

当选择一个单元加载其他UITableView时,如何才能对第二个表视图使用第一个plist中的<string>从url获取其他plist呢?

例如:

代码语言:javascript
复制
NSMutableArray *genres = [[NSMutableArray alloc] initWithContentsOfURL:[self.loadGenres objectForKey:@"PLIST URL"]];
self.loadGenres = genres;

感谢您的支持。

EN

回答 2

Stack Overflow用户

发布于 2013-03-27 21:08:43

你不能在数组中使用键值编码。

而不是像这样尝试,

代码语言:javascript
复制
NSMutableDictionary * genres = [[NSMutableDictionary alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.myurl.com/file.plist"]];
self.loadGenres = genres; // your self.loadGenres must be Dictionary type

NSMutableDictionary * genres = [[NSMutableDictionary alloc] initWithContentsOfURL:[NSURL URLWithString:[[self.loadGenres objectForKey:@"PLIST URL"]stringValue]]];
self.loadGenres = genres;
票数 1
EN

Stack Overflow用户

发布于 2013-03-27 21:28:10

在YourClass.h中尝试以下内容

代码语言:javascript
复制
NSURLConnection* linksConnection;
NSMutableData* linksData;

在YourClass.m中

代码语言:javascript
复制
-(void) loadURL
{

NSMutableURLRequest* the_request = [NSMutableURLRequest requestWithURL:[NSURL        URLWithString:YOUR_URL]];
linksConnection = [[NSURLConnection alloc] initWithRequest:the_request delegate:self startImmediately:YES];

if(linksConnection != nil)
{
    linksData = [[NSMutableData data] retain];

}
}

-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
 [linksData setLength:0];
}

-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[linksData appendData:data];
}

-(void) connectionDidFinishLoading:(NSURLConnection *)connection
{

NSString *errorStr = nil;
NSPropertyListFormat format;
NSDictionary *propertyList = [NSPropertyListSerialization propertyListFromData:linksData
                                                              mutabilityOption:NSPropertyListImmutable
                                                                        format:&format
                                                              errorDescription:&errorStr];
NSMutableArray*  myArray = [[propertyList objectForKey:@"sample"] retain];
}

我相信这会对你有很大帮助

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15659227

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档