0

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

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

NSMutableArray *genres = [[NSMutableArray alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.myurl.com/file.plist"]];
    self.loadGenres = genres;

when choose a cel loading other UITableView, but how can says to a second table view to get other plist from url using <string>inside the first plist?

像一个:

NSMutableArray *genres = [[NSMutableArray alloc] initWithContentsOfURL:[self.loadGenres objectForKey:@"PLIST URL"]];
self.loadGenres = genres;

谢谢你的支持。

4

2 回答 2

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;
于 2013-03-27T13:08:42.783 回答
1

在 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];
}

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

于 2013-03-27T13:28:10.257 回答