0

I m actually new to developing iOS application. I currently developing an iPad application where there is two UIViewController (A and B). A is my parent view controller and B is my UITableView popover that don cover the entire A.

After a row select at B, i manage to dismissed B but it don reflect changes made to A. How do i reload the parent view or is a something like android called the onResume method. Or ways to solve this problem.

Please provide me with some pointers, have being stuck for hours. Thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Hoon
  • 115
  • 1
  • 11
  • You need to use delegate pattern. http://stackoverflow.com/questions/8055052/call-a-parent-view-controller-through-a-navigationcontroller/8055480#8055480 – user523234 Sep 16 '13 at 04:44

4 Answers4

0

It depends on the situation. I would suggest 2 ways:

  1. As someone mentioned before, you can make a delegate mechanism so that controller B can call something like -reloadData on controller A. This is a tight coupling but can solve your problem.

  2. You can post a NSNotification from controller B and then listen to it in controller A. In controller B:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // Do your logic here
    
        [[NSNotificationCenter defaultCenter] postNotificationWithName:@"SettingsSavedNotification" object:nil];
    
        // Dismiss B controller
    }
    

    And in controller A:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveSettingsSavedNotification:) name:@"SettingsSavedNotification" object:nil];
    
        // Proceed with controller/view setup
    }
    
    - (void)didReceiveSettingsSavedNotification:(NSNotification *)notification
    {
        // Reload data here
    }
    

    Don't forget to call -removeObserver:name:object: on controller A teardown.

Misha Karpenko
  • 2,168
  • 17
  • 18
-1

Use – popoverDidClose: NSPopover class delegate method for update your data, or you may use cocoa binding.

Nikolai Nagornyi
  • 1,312
  • 2
  • 11
  • 26
-1

Two things:

1) You want to make sure you are the delegate to the UIPopoverController you are using to show your popover view controller "B". See the docs here: https://developer.apple.com/library/ios/documentation/uikit/reference/UIPopoverControllerDelegate_protocol/Reference/Reference.html

Then you'll want to implement one of those methods, e.g.:

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
    // Reload my view controller "A"
}

2) How do you know which row was selected in view controller B? It's possible you're updating some singleton that both view controllers have access to, but a better design pattern might be to create your own protocol and for view controller "A" to conform to it. In that case view controller B should have a weak delegate property that it sends a message to when the user selects a row. Just look at another class that uses the delegate/protocol pattern to see how it works, you could even look at the .h file of UIPopoverController by CMD + clicking the class name, or CMD + Shift + O to the file name.

Jared Egan
  • 1,268
  • 1
  • 12
  • 19
-1

Cant you just use - (void)viewWillAppear:(BOOL)animated ?

AMAN77
  • 6,218
  • 9
  • 45
  • 60