简体   繁体   中英

iOS: Update folder structure in subfolder

In my universal iOS application I create a folder structure that is saved in a plist file. It is built like this:

  • [Array] Root
    • [Dictionary] Item 0
      • [String] Title
      • [Array] Children
        • [Dictionary] Item 0
        • [Dictionary] Item 1
    • [Dictionary] Item 1
      • [String] Title
      • [Array] Children
        • [Dictionary] Item 0
        • [Dictionary] Item 1
        • [Dictionary] Item 2
        • [Dictionary] Item 3
    • [Dictionary] Item 2
      • [String] Title
      • [Array] Children

With this structure I navigate through the folders. The contents of the current data source (always an array) are displayed in a table view. Now it may be that some data is changed. Therefore I want to refresh my table structure and the data to fill in. If this is done in the root folder there is no problem, but if I try it in any of the subfolders I can only refresh the current array. So if I navigate back to an upper level of the structure still the old data is used.

What would be good practice to update all of my data, but still stay in the currently selected folder (only if it still exists)?

Thanks in advance

how did you navigate into subfolder? if you use UINavigationController, you should reload your tableview when user navigate back. for example you can do this in viewWillAppear

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // Reload data in table view
    [self.tableView reloadData];
}

You could use notifications, so each view controller would listen for an update notification, and when your data changes you post the notification.

You could simply reload the table data in each view controller's viewWillAppear: method.

1, You have a class method which is for updating the plist like this: [MyMethod updatePlist];

2, You have a parent view controller which has viewWillAppear or viewDidAppear methods. In there, you call [MyMethod updatePlist].

3, All your viewController inherit parent view controller.

So every time when you load a new view controller view, it always updated the plist. If necessary, you can add processing stuff to show loading.

Is that helpful?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM