neena
neena

Reputation: 365

back arrow for popover on iPhone

I have a UIBarButtonItem as "Add" on a view. On my story board i have a UIViewController embedded in a UINavigationController. I have connected the "Add" button to the UINavigationController to show it as popover. It works fine on ipad because it show it as popover but on iphone it show it as a plain form. My assumption was that on iphone it will show me the back arrow because of navigation controller so that i can go back. i can go back easily on ipad because its a popover there and it can be dismiss easily by touching but on iphone i am stuck. Any idea how would i show the back arrow just for iphone so that i can have a back route. Regards, neena

Upvotes: 1

Views: 298

Answers (1)

arpan.r
arpan.r

Reputation: 1981

are you looking for something like this? http://gracefullycoded.com/display-a-popover-in-swift

you give your view the .Popover modalPresentationStyle and define its preferred size :

menuViewController.modalPresentationStyle = .Popover
menuViewController.preferredContentSize = CGSizeMake(50, 100)

then you present like this

let popoverMenuViewController = menuViewController.popoverPresentationController
popoverMenuViewController?.permittedArrowDirections = .Any
popoverMenuViewController?.delegate = self
popoverMenuViewController?.sourceView = sender
popoverMenuViewController?.sourceRect = CGRect(
    x: location.x,
    y: location.y,
    width: 1,
    height: 1)
presentViewController(
    menuViewController,
    animated: true,
    completion: nil)

Upvotes: 1

Related Questions