0

This is my first post on stackoverflow, so please forgive me if I make some mistakes.

I'm a relatively new app designer, and I have been working on a new app that I'm hoping to publish soon. I have recently run into an issue. I am not able to use UIActionSheet. While it displays fine, the buttons simply make the action sheet disappear. I have tried many things to no avail; I did everything that was suggested in this thread (made by someone with a similar but not identical problem). I have tested and made sure that the function is not called altogether by using NSLog. I have tried changing the showInView, although it doesn't seem like that should make a difference anyway. So anyway, here's my current code:

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    if ( event.subtype == UIEventSubtypeMotionShake )
    {
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"You Shook?" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"End Game" otherButtonTitles:@"Settings", nil];
        [actionSheet showInView:self.view];
    }

    if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )
        [super motionEnded:motion withEvent:event];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        UIAlertView *endGameAlertView = [[UIAlertView alloc] initWithTitle:@"End Game" message:@"Are you sure you want to end the current game?" delegate:nil cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
        [endGameAlertView show];

    }

    else
    {
        UIAlertView *unimplementedSettingsAlertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"This feature is not yet implemented" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
        [unimplementedSettingsAlertView show];
    }
}

As you can see, the actionSheet is triggered by shaking the device (which works perfectly), again, the only issue is that the buttons do nothing except for close the actionSheet. I'm using Xcode 5.0.2 on OSX 10.9.1. Let me know if I left out any important information. Thank you in advance!

~Junior

Community
  • 1
  • 1

2 Answers2

0

set the delegate to self

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"You Shook?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"End Game" otherButtonTitles:@"Settings", nil];
Dávid Kaszás
  • 1,877
  • 1
  • 16
  • 20
  • I get this error when I do that: `Sending 'ViewController *const __strong' to parameter of incompatible type 'id'` – JuniorGenius Dec 29 '13 at 18:34
  • in the header you have to show, that this UIViewController subclass implements the UIActionSheetDelegate interface, like this: YourViewController: UIViewController – Dávid Kaszás Dec 29 '13 at 18:38
0

Currently you are setting the actionSheet's delegate to nil because of which your delegate method is not getting called.

In your ViewController.h file, write like this:

@interface ViewController : UIViewController <UIActionSheetDelegate>

You have to set the delegate of your actionSheet in order to get the delegate method called.

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"You Shook?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"End Game" otherButtonTitles:@"Settings", nil];
san
  • 3,350
  • 1
  • 28
  • 40
  • Okay great, the error is gone now, thanks! However, when I attempt to run it, I get this error: `clang: error: linker command failed with exit code 1 (use -v to see invocation)` – JuniorGenius Dec 29 '13 at 18:44
  • You must be getting some error log with this. Does this error log mention any duplicate symbol or file not found error?? – san Dec 29 '13 at 18:53
  • Yes: ld: 3 duplicate symbols for architecture i386 – JuniorGenius Dec 29 '13 at 19:07
  • Okay, got it! I had accidentally added `#include AppDelegate.m` into my ViewController.m. Everything works beautifully now. Thank you! – JuniorGenius Dec 29 '13 at 23:43