我尝试使用initWithContentsOfURL:从其他plist文件加载plist文件
我解释说,我在我的主机中有一个使用plist文件的表视图,使用以下方法:
NSMutableArray *genres = [[NSMutableArray alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.myurl.com/file.plist"]];
self.loadGenres = genres;当选择一个单元加载其他UITableView时,如何才能对第二个表视图使用第一个plist中的<string>从url获取其他plist呢?
例如:
NSMutableArray *genres = [[NSMutableArray alloc] initWithContentsOfURL:[self.loadGenres objectForKey:@"PLIST URL"]];
self.loadGenres = genres;感谢您的支持。
发布于 2013-03-27 21:08:43
你不能在数组中使用键值编码。
而不是像这样尝试,
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;发布于 2013-03-27 21:28:10
在YourClass.h中尝试以下内容
NSURLConnection* linksConnection;
NSMutableData* linksData;在YourClass.m中
-(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];
}我相信这会对你有很大帮助
https://stackoverflow.com/questions/15659227
复制相似问题