UIPopoverController, Xcode 6, IOS 8 using Swift

前端 未结 3 1648
粉色の甜心
粉色の甜心 2021-02-04 22:13

I\'m having some trouble getting a UIPopover to appear using swift. The code that is commented out works fine in Objective-C, but doesn\'t work using Swift. When I tap the + in

3条回答
  •  时光取名叫无心
    2021-02-04 23:06

    It looks like your popover is nil. Where are you assigning/instantiating it?

    Try changing this:

    popover?.presentPopoverFromBarButtonItem(addBarButtonItem, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
    

    To this:

    if let pop = popover {
        pop.presentPopoverFromBarButtonItem(addBarButtonItem, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
    } else {
        NSLog("Error: Popover was nil")
    }
    

    I imagine you'll see that error message in your console. In the .XIB for your PlayerInformationTableViewController, do you have a UIPopoverController?

    If so, you probably need to ensure that the var popover is either (1) being manually instantiated in your awakeFromNib, or that it's an @IBOutlet and is being connected properly.

    Alternatively, can you simply use the popover already present in your playerInformationViewController?

提交回复
热议问题