我尝试使用initWithContentsOfURL:
我解释说,我有一个表格视图使用我的主机中的plist文件,使用此metod:
NSMutableArray *genres = [[NSMutableArray alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.myurl.com/file.plist"]];
self.loadGenres = genres;
当选择一个cel加载其他UITableView时,怎么能说到第二个表视图从第一个plist中使用<string>
从url获取其他plist?
喜欢:
NSMutableArray *genres = [[NSMutableArray alloc] initWithContentsOfURL:[self.loadGenres objectForKey:@"PLIST URL"]];
self.loadGenres = genres;
感谢您的支持。
答案 0 :(得分:1)
您不能在数组中使用键值编码。
相反尝试这样,
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 :(得分:1)
尝试以下方法 在YourClass.h中
NSURLConnection* linksConnection;
NSMutableData* linksData;
-(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];
}
我相信这会对你有很大的帮助