4

私はこのクラスを次のように実装しました:

#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:を実装するのを忘れたようです。それを追加すると動作します。Appleのエラーメッセージは文字化けしていました。

4

1 に答える 1

3

UIPopoverBackgroundViewのドキュメントによると、プロパティのセッターも実装する必要がありますUIPopoverBackgroundView(つまりarrowDirection、 とarrowOffset.)。実装にゲッターが追加されました。

于 2012-02-02T16:51:10.443 に答える