Search code examples
iphoneiosuiactionsheet

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];
}

Solution

  • 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
    
         }
    
    }