我按照以下方式实现了这个类:
#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”异常终止应用程序,原因:‘-UIPopoverBack背景视图l’必须由子类实现。‘
有人知道它认为我没有实现什么方法吗?这似乎只是一堆胡言乱语。谢谢!
编辑看起来我忘了实现setArrowOffset:。在添加了这个之后它就能工作了。苹果的错误信息被弄错了。
发布于 2012-02-02 16:51:10
根据UIPopoverBackgroundView文档,还需要为UIPopoverBackgroundView中的属性(即arrowDirection和arrowOffset)实现setter。您刚刚在您的实现中获得了getter。
https://stackoverflow.com/questions/9116122
复制相似问题