Reputation: 51
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
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
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