Refresh first view after rejecting Popover

I am switching from the first view controller (tableview) to the second view controller which is the tableview. After I'm not with the second view, I need to reload the table view in the first controller. popoverPresentationControllerDidDismissPopover gets called if I go outside of the popover, but what if there is another button in the second table view that navigates to the first? I usually need the user to click the Add button to get out of the table rather than outside the popover. I am leaving the external response as a cancel action.

Thank. Popper over the table

0


source to share


2 answers


The delegate method is popoverPresentationControllerDidDismissPopover

not called on programmatic deviation.

The solution is when you dismiss the popover by calling dismiss(animated:completion:)

you must also call the table view to reload the data.

So basically you are calling tableView.reloadData()

twice. One in popoverPresentationControllerDidDismissPopover

, one after dismiss(animated:completion:)

, which is in the cut method of the add button.

Update

From your screenshot I am assuming your first view controller (VC1) is the one on the second, second view controller (VC2) is the pop.

If so, you have two options:



  • In VC2, declare your own protocol to notify VC1 to reload the table, look at the data whenever a row is selected, and set a delegate in VC1 to VC2.
  • Instead of using the protocol, you can simply declare the block property in VC2. For example:

    @property (copy, nonatomic) void (^itemSelectedHandler)()

    ;

And when an item is selected, call this (still in VC2):

self.itemSelectedHandler();

      

Then in VC1, after initializing VC2, which is the popover, you process the block. For example:

vc2.itemSelectedHandler = ^{
    [vc1.tableView reloadData];
}

      

Unfortunately I have no experience with fast programming, so I have to use the c object code as an example.

+2


source


Swift 3.0 version:

Popover VC:

define property:

var dismissHandler: (() -> Void)!

      

calling this handler when the popover is rejected:



self.dismissHandler()

      

Parent VC:

pass a handler in the Segue preparation method

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    ...
    destinationVC.dismissHandler = {
        self.tableView.reloadData()
    }
    ...
}

      

0


source







All Articles