creating button for popover view anchor at run time

后端 未结 4 2007
误落风尘
误落风尘 2021-02-18 20:38

This may not be possible, but I\'m hoping someone will have an idea how to do it.

I have an app I\'m porting from iPhone only to Universal. On the iPhone, I\'m using a

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-18 21:29

    I had the same problem and solved it by creating a UIBarButtonItem in the Storyboard for the view controller but not part of the view hierarchy.

    In IB, Drag a bar button item to the dark bar below the view controller view, drop it next to the "First Responder" and "View Controller" icons. Create a (strong) IBOutlet for it. Then create a popover segue from it to the destination view controller by dragging from the bar button item to the destination. It seems like this is the only way to set it as the anchor. Choosing it as the anchor for an existing segue does not work (looks like an IB bug).

    enter image description here

    In viewDidLoad you can assign this bar button item to the navigationItem (or where ever you like) and the segue works as expected.

提交回复
热议问题