我實現自定義PopoverBackgroundView實現,如在Swift documentation規定我必須實現方法如下:UIPopoverBackgroundView contentViewInsets必須由子類
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 must be implemented by subclassers.
看起來像蘋果有一些亂碼異常,因爲這個子類as can be seen here,因爲我實現了contentViewInsets,但仍然得到錯誤。
這是怎麼了設置背景類的酥料餅在prepareForSegue方法:
popover.popoverBackgroundViewClass = SettingsPopoverBackgroundView.self
是不是?
任何人都可以看到我做錯了什麼?
我複製了你的代碼,我沒有得到任何錯誤。在構建過程中還是在運行時,您是否收到此錯誤? – rdelmar 2015-04-05 17:02:24
只是爲了確保您確實覆蓋了正確的方法:將'overwrite'關鍵字添加到最後3個函數中。 – luk2302 2015-04-05 17:02:27
@rdelmar運行時。 – andriosr 2015-04-05 19:13:16