我似乎无法将图像添加到此 UIBarButtonItem 而不会在触摸时崩溃:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
此代码添加了一个图像,但由于从 UIButton 分配给 UIBarButtonItem * 的指针类型不兼容,因此在触摸时它会崩溃:
//Setup Custom Button
UIButton *button = [[UIButton alloc] init];
button.frame = CGRectMake(0,0,44,44);
// [button addTarget:self action:@selector(showInfo) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.backBarButtonItem = button;
[button setBackgroundImage:imgIcon forState:UIControlStateNormal];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
[button release];
谢谢你的帮助