【问题标题】:EXC_BAD_ACCESS on adding uiimageview to custom uibutton on iPad 5.0 simulator but works on iPad 6.0 simulatorEXC_BAD_ACCESS 将 uiimageview 添加到 iPad 5.0 模拟器上的自定义 uibutton 但适用于 iPad 6.0 模拟器
【发布时间】:2013-03-23 19:48:51
【问题描述】:

我的 .h 文件

#import <UIKit/UIKit.h>

@interface NavigationBarButton : UIButton

@property(nonatomic, retain) UIImageView *barButtonImage;

@property(nonatomic, retain) UILabel *barButtonLabel;

- (id)initWithFrame:(CGRect)frame withImage:(UIImage *) image withTitle:(NSString *) title;

我的 .m 文件

- (id)initWithFrame:(CGRect)frame withImage:(UIImage *) image withTitle:(NSString *) title


{

self = [super initWithFrame:frame];

if (self) 

{  
        self = [UIButton buttonWithType:UIButtonTypeCustom];

        self.frame = frame;
        self.backgroundColor = [UIColor clearColor];

        barButtonImage = [[[UIImageView alloc] initWithFrame:CGRectMake(16, 1, 18, 23)]autorelease];
        [barButtonImage setImage:image];

        barButtonLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 26, 50, 10)]autorelease];
        barButtonLabel.backgroundColor = [UIColor clearColor];
        barButtonLabel.text = title;
        barButtonLabel.font = [UIFont systemFontOfSize:11];
        barButtonLabel.textAlignment = NSTextAlignmentCenter;

        [self addSubview:barButtonLabel];
        [self addSubview:barButtonImage];

        //[barButtonImage release];
        //[barButtonLabel release];
    }
    return self;
}

但是应用程序在 [self addSubview:barButtonLabel] 上崩溃了,这很奇怪,因为代码在 iPad 6.0 模拟器上运行良好,但在 iPad 5.0 或 iPad 5.1 模拟器上却不能运行

【问题讨论】:

    标签: objective-c ipad ios-simulator


    【解决方案1】:

    检查一下这个

    在.m文件中添加这个

    @synthesize barButtonImage, barButtonLabel;
    

    【讨论】:

    • 是的,它现在可以工作了,但我认为问题出在其他问题上,因为它引发了错误......感谢您的回复
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多