在iPad 5.0模拟器上将uiimageview添加到自定义uibutton的EXC_BAD_ACCESS,但适用于iPad 6.0模拟器

时间:2013-04-02 13:30:12

标签: objective-c ipad ios-simulator

我的.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模拟器上运行不正确

1 个答案:

答案 0 :(得分:0)

一旦检查了这个

在.m文件中添加此内容

@synthesize barButtonImage, barButtonLabel;