Properly dismissing either popover ViewController or modal ViewController

I am building a universal App which is supposed to present a view controller to add stuff. On iPad, this is presented in a popover and on iPhone in a modal viewController. I am using the presenting ViewController as a delegate.

Now, if I want to assign the properController, I have to:

if([[segue identifier] isEqualToString:@"popoverAddSegue"])  
    self.myPopOver = [(UIStoryboardPopoverSegue * )segue popoverController];
if([[segue identifier] isEqualToString:@"modalAddSegue"])
    self.myModalView = [segue destinationViewController];

thus using two properties and only ever assigning one. Then, in my delegate function, I again have to differentiate:

    [self.myPopOver dismissPopoverAnimated:YES];
    [self.myModalView dismissViewControllerAnimated:YES completion:nil];

The problem obviously is that UIPopoverController does not inherit from UIViewController... Is there any elegant way of doing this? Factory or something? I hate having customised code in a viewController that should be agnostic about how it presents its viewControllers...


I use this

 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
     // The device is an iPhone or iPod touch.
 } else {
     // The device is an iPad => show library true popover.

This is not exactly what you ask for, but it have a good point : you can have the same segue identifier for both iPhone and iPad.

Now to have 1 similar method for both (popover / modalVC), may be you can add to both a new category with a method name dismissAnimated:

Need Your Help

On first back button press, softkeyboard should not go sown

java android

I have one Activity which contain one Edittext, On launching App Edittext come with Soft keyboard, As shown in above figure

Copy Content of Integer regarding endianess

c++ c c++11

What I want to do should actually be quite simple, but I don't know how to achieve it in a simple way: