views:

10

answers:

0

The plist has the file suffix .xml and is a normal array of dictionaries.

In the app delegate:

#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 my 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 sets lochusData to 0x0. This the part of code I'm asking about, really. The rest is more for completion. cacheFile returns the local filepath or an empty string. All the values are correct, but it just won't load / go into the array.

Feeling dumb. I just don't see the error. Is there something I'm missing?