Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For reusable code, you only want one version of <code>PopViewController</code>. Your two versions look identical, so get rid of one. In InterfaceBuilder, set your buttons to all segue to a single PopViewController. Root View Controller, then, looks like this:</p> <pre><code>@property (strong, nonatomic) IBOutlet UIButton *btnOpenPopover1; @property (strong, nonatomic) IBOutlet UIButton *btnOpenPopover2; </code></pre> <p>In <code>prepareForSegue:</code>, rather than segue to one version or another of <code>PopViewController</code>, just segue to your single version. Add a property to Root View Controller, to keep track of it (this replaces pvc1 and pvc2):</p> <pre><code>@property (strong, nonatomic) PopViewController* currentPopoverController; </code></pre> <p>You also need to keep track of which button is being edited, so add a property to your Root View Controller for that (note the weak reference):</p> <pre><code>@property (weak, nonatomic) IBOutlet UIButton* currentButton; </code></pre> <p>Set both of these in <code>prepareForSegue:</code>, so it looks like this:</p> <pre><code>-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { currentPopoverController = [segue destinationViewController]; [currentPopoverController setDelegate:self]; currentButton = (UIButton*) sender; } </code></pre> <p>Now, you only need one delegate that looks like this:</p> <pre><code>- (void)dismissPop:(NSString *)value { [currentButton setTitle:value forState:UIControlStateNormal]; [currentPopoverController dismissPopoverAnimated:YES]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload