how to implement popover for 'cocoa touch framework' component?

98 views Asked by At

Question: How does one implement (guess I mean by IOS best practice) a modal popover within a 'cocoa touch framework'?

Assumption here being it's a universal app so will support both iPhone and iPad. Could assume storyboard is being used for the main app that uses the cocoa touch framework.

For example, is best practice for the component to have to pass back a "please ask the user for info X,Y,Z to the main app and its view controller then use an approach like:

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let controller = storyboard.instantiateViewController(withIdentifier: "EventPopover")
    controller.modalPresentationStyle = .popover
    self.present(controller, animated: true, completion: nil)

This would be difficult and then the app would need to be built a bit for the component (/framework) used, so this wouldn't seem possible? Alternative maybe to manually create a pop up view oneself within the component, however not sure whether you would benefit from an IOS best practice approach that would help support iPad and iPhone re the normal popover approach?

Example may be, say you have a custom map component you want the user to be able to drop in, but one aspect of the component is that when a user chooses/drops a pin you want to be able to throw up a modal dialog to ask the user to customise the name for this dropped pin.

(hope this makes sense)

1

There are 1 answers

0
Greg On BEST ANSWER

I found using the UIViewController's popover mechanism is the approach, noting it will show a popover for iPad and for iPhone use the full screen.

   let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let controller = storyboard.instantiateViewController(withIdentifier: "EventPopover")
    controller.modalPresentationStyle = .popover
    self.present(controller, animated: true, completion: nil)