1

I'm having troubles with my UIActionSheet on iPad view. I really have no idea why I can press any button available on the current view when it is active.

Example: BarButtonItem pressed. UIActionSheet appears like a popover, while it is showing you can press Back BarButtonItem.

Is there any way to avoid this? I've tried this on iPhone view and it's pretty fine.

Rence
  • 55
  • 10
  • can you post your code here. – Ganesh Kumar Sep 15 '14 at 09:03
  • @Ganesh, the typical way you initialize an action sheet then `[action showFromBarButtonItem:sender animated:YES];` – Rence Sep 15 '14 at 09:09
  • posted my code in answer check it out. – Ganesh Kumar Sep 15 '14 at 09:15
  • hey @Ganesh, thanks for that. Will check it out once I get home. :) Thanks. Just wondering why do you still do the `@sythesize` thing? We already have Automatic Property Synthesis starting xCode 4.4 I believe. – Rence Sep 15 '14 at 09:22
  • when we create a property we must implement @synthesize and also check this link for reference .http://useyourloaf.com/blog/2012/08/01/property-synthesis-with-xcode-4-dot-4.html – Ganesh Kumar Sep 15 '14 at 09:27
  • Currently. It is just OPTIONAL to add starting from xCode 4.4 :)you may check this [link](http://stackoverflow.com/questions/15606151/objective-c-is-synthesize-required-or-optional) – Rence Sep 15 '14 at 09:50
  • Yes.I accept it.From my reference,if you want specify something we have to use @Synthesize otherwise (!) it will show like this in our project app. – Ganesh Kumar Sep 15 '14 at 10:00

1 Answers1

0

Try like this. First create a property

@property (weak, nonatomic) UIActionSheet *actionSheet;
@synthesize actionSheet = _actionSheet;

After that button action

- (IBAction)clickActionSheet:(UIBarButtonItem *)sender {
if (self.actionSheet) {
    // do nothing
} else {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Action sheet demo" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Do something else" otherButtonTitles:DO_SOMETHING_ELSE, nil];
[actionSheet showFromBarButtonItem:sender animated:YES];
}   
}

Implement this UIActionSheetDelegate

  -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex(NSInteger)buttonIndex
{
NSString *choice = [actionSheet buttonTitleAtIndex:buttonIndex];
if (buttonIndex == [actionSheet destructiveButtonIndex]) {
    // destroy something
    NSLog(@"Destroy");
} else if ([choice isEqualToString:DO_SOMETHING_ELSE]){
    // do something else
    NSLog(@"Do something else");
}
}
Ganesh Kumar
  • 708
  • 6
  • 25
  • Somehow. This how my code actually looks alike apart from that I'm just wondering why you need to set a property for `UIActionSheet` and `@Synthesize` it? – Rence Sep 15 '14 at 09:25