small medium large xlarge

03 Jun 2013, 06:22
brinthusha mahalingam (1 post)

Hi in my app, need to download the json data for the 1st time when the user install the app , then for the 2nd time need to reuse the downloaded data even witout internet connection also. for that i have used “NSUserdefault” but i couldnt access the data in offline.. please help me to sort out this issue.. im really fed up… this is my code:

//load json

-(void)viewDidAppear:(BOOL)animated {

  _feed = [[data alloc] initFromURLWithString : @""
                                 completion:^(JSONModel *model, JSONModelError *err) {
                                     //json fetched
                                     NSLog(@"Projects: %@", _feed.Projects);
                                     //reload the table view
                                     [self.collectionView reloadData];
                                 }]; }

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return _feed.Projects.count; }

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

NSUserDefaults *saved=[NSUserDefaults standardUserDefaults];

model* bankIcons=_feed.Projects[indexPath.row];

[saved setObject:bankIcons.logo forKey:@"_feed"];

[saved synchronize];

NSString *savedval=[[NSUserDefaults standardUserDefaults]stringForKey:@"_feed"];

custom *cell = [collectionView

UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:savedval]]];
 cell.displayImage.image = image;
return cell;