views:

43

answers:

1

Hi frieds,

I have created tool bar and set the UIBarbuttonItem in that tool bar.When i clicks the bar button, i have just removed one custom view. I want to avoid the multiple touches of the bar button items, because sometimes the user clicks the bar button items more than one.( It happens some time only).

Here my sample code,

     UIBarButtonItem *closeBtn =[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(action)] autorelease];

    toolBar.items = [NSArray arrayWithObjects:space,closeBtn,nil];

     -(void) action
     {
         [customView removeFromSuperview];
     }

So i want to avoid the multiple touch, when clicks the bar button in the tool bar. And how can i detect to the bar button is select?. So how can i avoid this problem? Please help me out.

Thanks!

+1  A: 

There are several possible approaches, but one is to set the button to disabled. You'll need to change your action method a bit.

 -(void) action:(id)sender
 {
     if ([sender isKindOfClass:[UIBarItem class]]) {
         [sender setEnabled:NO];
     }
     [customView removeFromSuperview];
 }
Robot K