gpt4 book ai didi

ios - 实现 UIPopoverBackgroundView 子类时出现乱码异常

转载 作者:可可西里 更新时间:2023-11-01 05:47:11 26 4
gpt4 key购买 nike

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

#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];

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

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

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

编辑 看来我忘了实现 setArrowOffset:。添加后它起作用了。 Apple 的错误消息只是乱码。

最佳答案

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

关于ios - 实现 UIPopoverBackgroundView 子类时出现乱码异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9116122/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com