user1779598
user1779598

Reputation: 51

Get UIActionSheet to perform action

This a rookie question.. I created the UIActionSheet. Now how do i get it perform "delete" when its pressed.

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    if (event.subtype == UIEventSubtypeMotionShake )
    {
        // Handle shake notification
    UIActionSheet *shakeActionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                                  delegate:self
                                                         cancelButtonTitle:@"Cancel"
                                                    destructiveButtonTitle:@"Delete"
                                                         otherButtonTitles:nil];

    [shakeActionSheet showInView:self];
    }

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

Upvotes: 0

Views: 755

Answers (3)

AC1
AC1

Reputation: 463

Just to add on to other two solutions, you can add the delegate in your - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event method like this (assuming your class implements UIActionSheetDelegate protocol):

shakeActionSheet.delegate = self;

Upvotes: 0

SpaceDust__
SpaceDust__

Reputation: 4914

try to call UIActionSheet delegate methods

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{

    NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];

    if([title isEqualToString:@"Delete"])
    {
     //do your stuff in here

     }

}

Upvotes: 2

SAE
SAE

Reputation: 1739

Your class has to conform to the UIActionSheetDelegate protocol.

Then override the actionSheet:clickedButtonAtIndex: method, evaluate the clicked button and act accordingly.

See here for more info.

Upvotes: 1

Related Questions