Frage

Die plist hat die Datei-Suffix .xml und ist ein normales Array von Wörterbüchern.

In der AppDelegate:

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

In meinem Tableview Controller:

#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 setzt lochusData auf 0x0. Dies ist der Teil des Codes Ich bitte um, wirklich. Der Rest ist für die Fertigstellung. cachefile gibt den lokalen Dateipfad oder einen leeren String. Alle Werte sind korrekt, aber es wird nur nicht geladen / gehen in das Array.

Gefühl stumm. Ich sehe nur nicht den Fehler. Gibt es etwas, was ich bin fehlt?

War es hilfreich?

Lösung

Antwort war: "Ihr charset Überprüfen Sie, wenn die erzeugte XML speichern, dude":)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top