BlackSheep
BlackSheep

Reputation: 1087

Loadin URL for Plist from Plist

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.

Upvotes: 0

Views: 139

Answers (2)

hariszaman
hariszaman

Reputation: 8424

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

Upvotes: 1

Vedchi
Vedchi

Reputation: 1210

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;

Upvotes: 1

Related Questions