0

plistのファイル拡張子は.xmlで、通常の辞書の配列です。

アプリデリゲート:

#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は、ローカルファイルパスまたは空の文字列を返します。すべての値は正しいですが、配列にロード/配置されません。

馬鹿げた感じ。エラーが表示されません。足りないものはありますか?

4

1 に答える 1

0

答えは、「生成されたXMLを保存するときに文字セットを確認してください」でした:)

于 2010-12-08T22:58:57.143 に答える