Search code examples
iosuitableviewplistreload

How to reload a plist file into a table


I have a Plist file (outside the bundle) that I use to store the users favourites. Once loaded it works as expected the Plist is loaded into the table.

However, when you add a new item to the Plist: the plist file (outside the bundle) updates. The reload tableview is triggered as shown in the log. However, the data is not actually reloaded from the Plist it just uses the existing (Array) values. Unless you quit and reload the whole app in which case the updated Plist appears in the table.

How can I make my table actually reload from the updated Plist rather than just using the original array.

Thanks.

I use this code to get the data from the Plist - working.

 NSMutableArray *rawFavArray = [[NSMutableArray alloc] initWithContentsOfFile:plistPath];

I use this to run through array to create cell info for table - working.

 return [favReloadArray objectAtIndex:indexPath.row];

I use this to reload table (within viewWillApear) - not working, triggers log, but does not reload the Plist.

 [self.tableView reloadData];

When I try an change the data in the Plist - I can do this but any changes do not show up in the table unless I quit app and start again.


Solution

  • Just before you call reloadData you should have [favReloadArray release]; favReloadArray = [[NSMutableArray alloc] initWithContentsOfFile:plistPath];
    or
    favReloadArray = [NSMutableArray arrayWithContentsOfFile:plistPath];
    depending on which way you first create favReloadArray.