Iphone 更改背景的自定义导航栏以及自定义“后退”按钮存在问题
我对UINavigationBar进行了子类化,并添加了如下自定义背景:Iphone 更改背景的自定义导航栏以及自定义“后退”按钮存在问题,iphone,objective-c,ios,cocoa-touch,Iphone,Objective C,Ios,Cocoa Touch,我对UINavigationBar进行了子类化,并添加了如下自定义背景: @implementation CustomUINavigationBar @synthesize backImg; - (void)drawRect:(CGRect)rect { if (backImg != nil) { [backImg drawInRect:CGRectMake(rect.origin.x, rect.origin.y, backImg.size.width, backI
@implementation CustomUINavigationBar
@synthesize backImg;
- (void)drawRect:(CGRect)rect {
if (backImg != nil) {
[backImg drawInRect:CGRectMake(rect.origin.x, rect.origin.y, backImg.size.width, backImg.size.height)];
}else{
[super drawRect:rect];
}
}
-(void)setBackImg:(UIImage *)nBackImg{
backImg = nBackImg;
if (backImg != nil) {
[self setNeedsDisplay];
}
}
setBackImg在app委托中被调用,这取决于我在navigationcontroller中加载的视图控制器
在视图控制器本身中,我执行以下操作:
- (void)viewDidLoad
{
[super viewDidLoad];
//Custom back button
// Set the custom back button
UIImage *buttonImage = [UIImage imageNamed:@"back.png"];
//create the button and assign the image
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
//set the frame of the button to the size of the image (see note below)
button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
//create a UIBarButtonItem with the button as a custom view
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = customBarItem;
[customBarItem release];
}
现在它确实出现了,但(有时)当我按下它或视图控制器的内容时(总是)会导致未捕获的异常:
'NSInvalidArgumentException', reason: '-[UIButton setTracking:]: unrecognized selector sent to instance 0x4f62840
回答(还不能回答我自己的问题):
原来是IOS5中的一个bug,通过降级修复。将填充错误报告。因为您正在向setTracking方法传递无效参数(我不知道它是您的方法还是内置的),例如需要非nil对象的nil指针。第二个原因可能是您没有正确管理视图控制器的内存,并且它在某个点被释放-这导致back:方法被发送到另一个对象,该对象现在正在占用视图控制器以前占用的内存 原来是IOS5中的一个bug,通过降级修复。将填写错误报告。我假设这个类中存在一个名为“back”的方法?是的,它会弹出视图控制器和其他内容。这一直有效。现在你可以回答你自己的问题了。。