質問

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