[英]Adding Custom Back Button on NavigationBar UIButton buttonWithTypw:101 not working
我使用了下面提到的代码作为自定义的左指向左按钮,它可以正常工作..但是几天后,它又变回了矩形按钮。 .. 谢谢...
UIButton *backButton = [UIButton buttonWithType:101];
[backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
[backButton setTitle:@"Back" forState:UIControlStateNormal];
UIBarButtonItem* newBackButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
graphSecondViewCtrl.navigationItem.leftBarButtonItem = newBackButton;
按钮类型101
未记录。 苹果并没有同意维护它,因此它可以随时更改。 依靠这些东西是不正确的。 您应该考虑使用带有图像的custom
按钮,以确保它不会像现在那样损坏。
SDK中未定义按钮类型101,并且可以在任何OS升级后停止工作。
我将使用buttonWithType:UIButtonTypeCustom
,然后通过在自定义按钮对象上调用setImage:forState来添加图像,以提供所需的外观。
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:[UIImage imageNamed:@"backBarButtonNormal.png"] forState:UIControlStateNormal];
[backButton setImage:[UIImage imageNamed:@"backBarButtonHighlighted.png"] forState:UIControlStateHighlighted];
// Rest of the code is the same.
真正的问题是,为什么您需要重新创建导航控制器首先自动为您提供的标准按钮。 确保使用工具,而不是反对工具。
如果需要跟踪何时交换视图控制器的时间,可以将视图控制器设置为导航控制器的委托,如下所示:
- (void)viewDidLoad {
[super viewDidLoad];
[[self navigationController] setDelegate:self];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (viewController != self)
NSLog(@"We're going away...");
}
- (void)viewDidUnload {
[super viewDidUnload];
[[self navigationController] setDelegate:nil];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.