首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >实现UIPopoverBackgroundView子类时的混淆异常

实现UIPopoverBackgroundView子类时的混淆异常
EN

Stack Overflow用户
提问于 2012-02-02 16:37:36
回答 1查看 1.6K关注 0票数 4

我按照以下方式实现了这个类:

代码语言:javascript
复制
#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

我使用以下代码将其添加到我的UIPopoverView (而不是子类)中:

代码语言:javascript
复制
_logoutPopover.popoverBackgroundViewClass = [JKBackgroundView class];

但是,当我运行该项目时,会收到如下疯狂的错误消息:

*由于“NSInternalInconsistencyException”异常终止应用程序,原因:‘-UIPopoverBack背景视图l’必须由子类实现。‘

有人知道它认为我没有实现什么方法吗?这似乎只是一堆胡言乱语。谢谢!

编辑看起来我忘了实现setArrowOffset:。在添加了这个之后它就能工作了。苹果的错误信息被弄错了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-02 16:51:10

根据UIPopoverBackgroundView文档,还需要为UIPopoverBackgroundView中的属性(即arrowDirectionarrowOffset)实现setter。您刚刚在您的实现中获得了getter。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9116122

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档