As my title said that clickedButtonAtIndex
delegate method is call even tap on out side of UIActionSheet.
My actionSheet is display when I tapped on UIButton
.
Code of my UIActionSheet
declaration.
-(void)btnComplexityTapped:(UIButton *) sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select your complexity" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Easy", @"Medium", @"High", nil];
[actionSheet showFromRect:sender.frame inView:self.view animated:YES];
[actionSheet release];
}
And in delegate method
- (void)actionSheet:(UIActionSheet *)myActionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
[self.btnComplexity setTitle:@"Easy" forState:UIControlStateNormal];
}
else if(buttonIndex == 1)
{
[self.btnComplexity setTitle:@"Medium" forState:UIControlStateNormal];
}
else
{
[self.btnComplexity setTitle:@"High" forState:UIControlStateNormal];
}
}
I know that this issue is fix by set last condition in delegate method to set else if(buttonIndex == 1)
instead of only else
. But I does not want to apply any fixing but I want to know why delegate method is called even I am not tapping on any button of UIActionSheet
See this video for more clear picture.
As above video default title of button is "Medium" when I click on button then actionSheet is open and I click on out side of actionSheet (such like self.view
) then delegate method clickedButtonAtIndex
is called so last else
condition is become true and thats way my button's title is changed "High".
Can any body tell my why this is happening ?
In iPad action sheet is presented in a popover. No cancel button because touching out of popover is equivalent to a touch on cancel. So, your delegate receives the message as if cancel button has been touch.