Garbled exception when implementing UIPopoverBackgroundView subclass

不问归期 提交于 2019-12-10 15:56:56

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/9116122/garbled-exception-when-implementing-uipopoverbackgroundview-subclass

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