Is there a way to select a segue anchor programmatically?

前端 未结 4 1988
有刺的猬
有刺的猬 2021-02-07 09:54

Suppose I have a Storyboard containing a view that contains a button. When the user presses this button, a popover comes up.

Thus, I need to set an anchor by dragging th

4条回答
  •  再見小時候
    2021-02-07 10:25

    In the storyboard anchor the popover to some arbitrary button. Don't worry too much about which one as it will get overridden in the code.

    In the view controller method prepareForSegue, add the code:

    let dest = segue.destinationViewController
    dest.popoverPresentationController?.barButtonItem = 
    

    or if you want to anchor to a view instead

    dest.popoverPresentationController?.barButtonItem = nil
    dest.popoverPresentationController?.sourceView = 
    

提交回复
热议问题