Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBarButtonItem, set exclusive touch

Is there a way to make UIBarButtonItem exclusive touch? At the moment you can select multiple at the same time and it keeps crashing my application.

like image 935
Mike Mellor Avatar asked Jul 10 '12 09:07

Mike Mellor


3 Answers

Slightly easier method than subclassing the navbar but the same idea;

for(UIView *temp in self.navigationController.navigationBar.subviews)
{
    [temp setExclusiveTouch:YES];
}

Put this just after you add your bar button items.

like image 189
Mike Mellor Avatar answered Oct 30 '22 15:10

Mike Mellor


I managed this problem by subclassing UINavigationBar and overriding layoutSubviews method. Something like this:

- (void)layoutSubviews {
    [super layoutSubviews];
    for (UIView *view in self.subviews) {
        view.exclusiveTouch = YES;
    }
}
like image 31
kengura Avatar answered Oct 30 '22 14:10

kengura


Dredging up the past I apologise. I stumbled into this and hoped there was a better way than looping through subviews.

I found that the following makes the UIBarButtonItems exclusive:

[self.navigationController.navigationBar setExclusiveTouch:YES]; 

iOS7 may have made exclusive touch inherited.

like image 33
William George Avatar answered Oct 30 '22 14:10

William George