UIPopoverBackgroundView contentViewInsets必须由子类实现

时间:2015-04-05 16:46:14

标签: ios swift uipopoverbackgroundview

我正在实现一个自定义的PopoverBackgroundView,并且正如Swift documentation所指定的,我必须实现以下方法:

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
}
}

但是,我仍然收到错误:

  

UIPopoverBackgroundView contentViewInsets必须由。实现   子类。

对于这个子类化as can be seen here,似乎Apple有一些乱码异常,因为我确实实现了contentViewInsets,但仍然得到错误。

这就是我在prepareForSegue方法中将后台类设置为popover的方法:

popover.popoverBackgroundViewClass = SettingsPopoverBackgroundView.self

是不是?

谁能看到我做错了什么?

1 个答案:

答案 0 :(得分:9)

contentViewInsets()arrowBase()arrowHeight()都是类功能,因此您需要在func前面使用“覆盖类”。

对于arrowOffsetarrowDirection,文档说您的方法不得称为超级。我不确定你需要在那些装置中放置什么(这取决于你想要做什么),但是如果你把它们留空,应用程序应该没有错误地运行(尽管你不会看到箭头)。