Question

I've implemented this class as follows:

#import "JKBackgroundView.h"

@implementation JKBackgroundView

static CGFloat jkArrowBase = 26.0;
static CGFloat jkArrowHeight = 16.0;

// Background image insets
static CGFloat jkBackgroundTopInset = 68.0f;
static CGFloat jkBackgroundLeftInset = 16.0f;
static CGFloat jkBackgroundBottomInset = 16.0f;
static CGFloat jkBackgroundRightInset = 34.0f;

// Content view insets
static CGFloat jkContentTopInset = 40.0f;
static CGFloat jkContentLeftInset = 6.0f;
static CGFloat jkContentBottomInset = 8.0f;
static CGFloat jkContentRightInset = 7.0f;

+(CGFloat)arrowBase {
    return jkArrowBase;
}

-(UIPopoverArrowDirection)arrowDirection {
    return UIPopoverArrowDirectionUp;
}

-(CGFloat)arrowOffset {
    return 0.0f;
}

+(CGFloat)arrowHeight {
    return jkArrowHeight;
}

+(UIEdgeInsets)contentViewInsets {
    return UIEdgeInsetsMake(jkContentTopInset, jkContentLeftInset, jkContentBottomInset, jkContentRightInset);
}

-(void)drawRect:(CGRect)rect {
    UIEdgeInsets popoverInsets = UIEdgeInsetsMake(jkBackgroundTopInset, jkBackgroundLeftInset, jkBackgroundBottomInset, jkBackgroundRightInset);
    UIImage *popoverImage = [[UIImage imageNamed:@"popover_stretchable.png"] resizableImageWithCapInsets:popoverInsets];
    [popoverImage drawInRect:rect];
}

-(id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

-(void)setArrowDirection:(UIPopoverArrowDirection)arrowDirection {
    // Do nothing
}

@end

I add it to my UIPopoverView (not a subclass) using this code:

_logoutPopover.popoverBackgroundViewClass = [JKBackgroundView class];

When I run the project, though, I receive a crazy error message as follows:

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIPopoverBackgroundView º¯lå] must be implemented by subclassers.'

Does anyone has any idea what method it thinks I didn't implement? It appears to just be a bunch of gibberish. Thanks!

Edit It looks like I forgot to implement setArrowOffset:. It works after adding that. Apple's error message was just garbled.

Was it helpful?

Solution

According to the docs for UIPopoverBackgroundView you are required to also implement setters for the properties in UIPopoverBackgroundView (i.e. arrowDirection and arrowOffset.) You've just got the getters in your implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top