In my main view controller i create custom 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;

}

It worked until iOS 7 came. On iOS 7 when the app is first launched the button doesn't show at all. However, when built and launched again the button is there and works ok. Any idea how this could be fixed?

有帮助吗?

解决方案 2

It turns out the trouble was in my controllers stack, fixing that fixed my problem

其他提示

I'm not sure why that doesn't work. Try doing it like this:

- (UIBarButtonItem *)carSelectBarItem {
UIButton *button = [[UIButton alloc] init];

[button setImage:[UIImage imageNamed:@"IconCar.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(reloadUI)
    forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 30, 30)];

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc]
                           initWithCustomView:button];

return barButtonItem;
}

And then in your viewDidLoad method:

[self.navigationItem setLeftBarButtonItem:[self carSelectBarItem]];

You'll probably need to change the frame from (0, 0, 30, 30)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top