【问题标题】:Garbled exception when implementing UIPopoverBackgroundView subclass实现 UIPopoverBackgroundView 子类时出现乱码异常
【发布时间】:2012-02-03 01:48:29
【问题描述】:

我已经按如下方式实现了这个类:

#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(不是子类):

_logoutPopover.popoverBackgroundViewClass = [JKBackgroundView class];

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

* 由于未捕获的异常 'NSInternalInconsistencyException' 导致应用程序终止,原因:'-[UIPopoverBackgroundView º¯lå] 必须由子类实现。'

有谁知道它认为我没有实现什么方法?它似乎只是一堆乱码。谢谢!

编辑 看来我忘了实现 setArrowOffset:。添加后它可以工作。苹果的错误信息只是乱码。

【问题讨论】:

  • 你也可以给我们看看界面吗?

标签: ios uipopover


【解决方案1】:

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

【讨论】:

  • 应该用一些合成来修复。
  • @JoePasq true 但在这种情况下不一定正确。首先,这取决于他尚未与我们共享的界面:如果属性是atomic,那么您不能将合成的 setter 与手工制作的 getter 混合使用。这里不太可能,但需要考虑。其次,他需要自己滚动的吸气剂来强制返回他的静态箭头高度和偏移量;考虑到这一点,如果他手动实现 setter 则更具可读性,因为它们实际上不会做任何事情(如果他合成,他们将设置永远不会读取的“幻像”ivars。)这很难看。
  • 我意识到这是缺少实现方法的问题,但是错误消息是乱码。我需要帮助来弄清楚我错过了什么。谢谢大家!
  • 对,那会很丑,而且会有幻影。呵呵,我不知道你不能和atomic混在一起。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-03
  • 1970-01-01
  • 1970-01-01
  • 2017-02-10
相关资源
最近更新 更多