Update a tableView with a plist took from another table

Posted by Pheel on Stack Overflow See other posts from Stack Overflow or by Pheel
Published on 2012-06-16T18:41:23Z Indexed on 2012/06/16 21:16 UTC
Read the original article Hit count: 282

Filed under:
|
|

Background:

I have a tab bar application, which has a tableView as the "heart" of the app. It loads data from a plist and, through a button that checks if there are any updates on the remote plist file, updates the local plist with the remote contents.

Then, i have another tableView, that should display only those plist items that have a bool value set to YES.

Now i want to add a button to the second table that reloads the plist took from the first table.

Expected:

When i update the local plist from the first table and when i press the button on the second table, the 2nd table is supposed to update and show the cells with that bool value set to YES.

(Note: I set YES as default to some items on plist).

What happens:

The first table updates its content from remote. The second table shows the old items with the value set to YES. When i press the button to refresh data, it reads the plist fine (by logging it, it has the same contents of the first table -only those set to YES-),but it doesn't update data even if i have [self.tableView reloadData];. When i close the app and open it again, the second table is filled with the right items. :\

Code i'm using:

//Reading Plist
{  
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
    NSString *plistPath = [[documentPaths lastObject] stringByAppendingPathComponent:@"myPlist.plist"]; 

    NSFileManager *fMgr = [NSFileManager defaultManager]; 
    if (![fMgr fileExistsAtPath:plistPath]) { 
        plistPath = [[NSBundle mainBundle] pathForResource:@"myPlist" ofType:@"plist"]; 

    } 

    NSMutableArray *returnArr = [NSMutableArray arrayWithContentsOfFile:plistPath]; 
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"isFav == YES"]; 

    for (NSDictionary *sect in returnArr) { 
        NSArray *arr = [sect objectForKey:@"Rows"]; 
        [sect setValue:[arr filteredArrayUsingPredicate:predicate] forKey:@"Rows"]; 
    } 
    [self.tableView reloadData];
}

//Refresh data button
- (void) refreshTable:(id)sender
{   

        NSLog(@"plist read");
        [self readPlist];
        NSLog(@"refreshed plist:%@",[self readPlist]);

        [self.tableView reloadData];
}

Does anyone know why the table is not updating?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about uitableview