Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPopoverBackgroundView contentViewInsets must be implemented by subclassers

I'm implementing a custom PopoverBackgroundView, and as specified at Swift documentation I gotta implement the methods as follow:

class SettingsPopoverBackgroundView: UIPopoverBackgroundView {

override var arrowOffset: CGFloat {
    get {
        return 0.0
    }
    set {
        super.arrowOffset = newValue
    }

}

override var arrowDirection: UIPopoverArrowDirection {
    get {
        return UIPopoverArrowDirection.Up
    }
    set {
        super.arrowDirection = newValue
    }
}

func contentViewInsets() -> UIEdgeInsets {
    return UIEdgeInsetsMake(10, 10, 10, 10)
}

func arrowBase() -> CGFloat {
    return 2.0
}

func arrowHeight() -> CGFloat {
    return 2.0
}
}

However, I'm still getting the error:

UIPopoverBackgroundView contentViewInsets must be implemented by subclassers.

It seems like Apple has some garbled exception as for this subclassing, as can be seen here, because I do implement contentViewInsets, but still get the error.

This is how I am settings the background class to the popover in the prepareForSegue method:

popover.popoverBackgroundViewClass = SettingsPopoverBackgroundView.self

Is it right?

Can anyone see what am I doing wrong?

like image 955
andriosr Avatar asked Apr 05 '15 16:04

andriosr


1 Answers

contentViewInsets(), arrowBase(), and arrowHeight() are all class functions, so you need "override class" in front of func for those.

For arrowOffset and arrowDirection, the docs say that your methods must not call super. I'm not sure exactly what you need to put in those setters (that depends on what you're trying to do), but if you leave them blank, the app should run with no errors (though you won't see an arrow).

like image 173
rdelmar Avatar answered Oct 24 '22 18:10

rdelmar