0

i try to load a plist file from other plist file using initWithContentsOfURL:

i explain, i have one table view using a plist file in my host, with this metod:

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?

Like a:

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

Thanks for support.

BlackSheep
  • 1,087
  • 12
  • 29

2 Answers2

1

You can't use Key-Value coding in Array's.

Instead try like this,

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;
Vedchi
  • 1,200
  • 6
  • 14
  • Hmmm i try it before, but the error message is: No visible @interface for 'NSMutableArray' declares the selector 'objectForKey:' – BlackSheep Mar 27 '13 at 13:14
1

try the following in YourClass.h

NSURLConnection* linksConnection;
NSMutableData* linksData;

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

I am sure this will help you a lot

hariszaman
  • 8,202
  • 2
  • 40
  • 59