Hasintha Janka
Hasintha Janka

Reputation: 1639

Not able to disable UIBarButtonItem in UIToolabar

I use code similar to following code make a custom toolbar. But it disabling functionality not working,

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStyleBordered target:self action:@selector(navigationCart:)];
    barButtonItem.image = [self imageCartIconNormal];
    barButtonItem.enabled = NO;

[self setToolbarItems:[[NSMutableArray arrayWithObjects:barButtonItem,barButtonItem1, barButtonItem2, nil] animated:YES];

Thank you in advance.

Upvotes: 0

Views: 215

Answers (1)

Mundi
Mundi

Reputation: 80271

Tested and working :

UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:nil 
   style:UIBarButtonItemStyleBordered target:self action:nil];
button.enabled  = NO;
button.image = [UIImage imageNamed:@"icon"];
[self.toolbar setItems:@[button] animated:YES];

Make sure your imageCartIconNormal returns a UIImage.
Make sure your setToolbarItems calls the method above on an UIToolbar.

NB: There is no use in a mutable array here.

Upvotes: 1

Related Questions