2

I follow this post to implement a UIPopoverBackgroundView. I checked the UIPopoverBackgroundView class, I think I have implemented all required functions and variables, but the error still persist when running .

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIPopoverBackgroundView setArrowOffset:] must be implemented by subclassers.'

import UIKit

class CustomPopoverBackground: UIPopoverBackgroundView {

    override func layoutSubviews() {
        super.layoutSubviews()
    }

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

    }

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

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

    override class func arrowBase() -> CGFloat {
        return 2.0
    }

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

}

Where did I wrong? What is setArrowOffset, I didn't find it in the class of UIPopoverBackgroundView or UIPopoverBackgroundViewMethods protocol.

Community
  • 1
  • 1
ilovecomputer
  • 4,238
  • 1
  • 20
  • 33

1 Answers1

0

Another blog post that actually shows the implementation of custom UIPopOverBackgroundView

It holds the Arrow in a struct

private struct Arrow {
    let height    : CGFloat   = 30.0
    let base      : CGFloat   = 20.0

    var direction : Direction = .UP
    var offset    : CGFloat   = 0.0
}

override var arrowOffset: CGFloat {
    get {
        return arrow.offset
    }

    set {
        arrow.offset = newValue
    }
}

No super call here, the class expects subclass to actually hold the value and not use the superclass implementation.

Shubhank
  • 21,721
  • 8
  • 65
  • 83