0
plist具有文件後綴.xml,並且是一個正常的字典數組。Plist文件存在於docs目錄中,但無法加載到數組中
在應用程序的委託:
#define docDir [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
-(NSString *)cacheFile:(NSString *)filename sitepath:(NSString *)url {
NSMutableString *retfn=[NSMutableString string];
NSString *mediaUrl=[NSString stringWithFormat:@"%@%@",url,filename];
if(nil != mediaUrl){
NSData* imageData;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
@try {
imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mediaUrl]];
}
@catch (NSException * e) { //error
NSLog(@"%@",@"CacheFile error!");
}
@finally { //save to Documents
[retfn appendFormat:@"%@%@%@",docDir,@"/",filename];
[imageData writeToFile:retfn atomically:YES];
}
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[imageData release];
}
return retfn;
}
在我的tableView控制器:
#define fname @"myplist.xml"
#define fdir @"http://mysite.com/iPhoneApp/"
- (void)viewDidLoad {
appdel=(EksjoHusAppDelegate *) [[UIApplication sharedApplication] delegate];
NSString *husDataF=[appdel cacheFile:fname sitepath:fdir];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:husDataF];
if (([husDataF length]>0)&&(fileExists)) {
NSMutableArray *lochusData=[[NSMutableArray alloc] initWithContentsOfFile:husDataF];
appdel.husData=lochusData;
[lochusData release];
}
}
initWithContentsOfFile設置lochusData爲0x0。這是我所問的代碼的一部分,真的。其餘更多用於完成。 cacheFile返回本地文件路徑或一個空字符串。所有的值都是正確的,但它不會加載/進入數組。
感覺啞巴。我只是沒有看到錯誤。有什麼我失蹤?
的代碼是正確的,問題是與內容類型/字符集。生成該文件的腳本將其保存在具有錯誤屬性的服務器上。仍然不會驗證,但工程。 – 2010-10-07 14:17:26