UIPopoverBackgroundView contentViewInsets must be implemented by subclassers

只谈情不闲聊 提交于 2020-01-24 03:44:25

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/29459668/uipopoverbackgroundview-contentviewinsets-must-be-implemented-by-subclassers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!