在我的主视图控制器中,我创建了自定义 leftBarButtonItem
- (void)viewDidLoad {
[super viewDidLoad];
RNObserveNotification(@"VTLoginSuccess", @selector(loginSuccess:));
[self checkIfRoleChanged];
self.navigationItem.leftBarButtonItem = [self carSelectBarItem];
}
- (UIBarButtonItem *)carSelectBarItem {
UIBarButtonItem *item = [self buttonItemWithText:@" " target:self action:@selector(changeVehicleAction:)];
VTCustomButton *button = (VTCustomButton *)[item customView];
UIImageView *carIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IconCar.png"]];
[button addSubview:carIcon];
button.titleEdgeInsets = UIEdgeInsetsMake(0, 18.0, 0, 0);
button.titleLabel.textAlignment = UITextAlignmentLeft;
CGRect frame = carIcon.frame;
frame.origin.x += 8;
frame.origin.y += 12;
carIcon.frame = frame;
self.currentVehicleButton = button;
return item;
}
它一直有效,直到 iOS 7 到来。在 iOS 7 上,当应用程序首次启动时,按钮根本不显示。但是,当构建并再次启动时,按钮就在那里并且工作正常。知道如何解决这个问题吗?