2013-03-27 57 views
0

我嘗試使用加載其他plist文件plist文件中initWithContentsOfURL:Loadin網址的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; 

謝謝支持。

+0

can你在這裏提到你file.plist的內容是什麼? – hariszaman 2013-03-27 13:00:01

+0

胡蘿蔔 spar.com圖像0​​ genresC.png文件 http://www.myurl.com/file.plist BlackSheep 2013-03-27 13:05:50

+0

我會得到一個文件字符串第二個TableView – BlackSheep 2013-03-27 13:06:17

回答

1

您不能在Array中使用Key-Value編碼。

而是嘗試這樣,

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; 
+0

嗯我以前嘗試,但該錯誤信息是:對「NSMutableArray的」不可見@interface聲明選擇「objectForKey:」 – BlackSheep 2013-03-27 13:14:20

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

我相信這將幫助你lot

+0

謝謝,但給ARC誤差在.m文件RETAIN – BlackSheep 2013-03-27 13:54:16

+0

你可以在你的項目禁用ARC除了它的設置是不是一個好習慣使用自動參考計數 – hariszaman 2013-03-27 13:56:04

+0

THX我嘗試它;) – BlackSheep 2013-03-27 14:02:59