问题描述
- UIActionSheet执行action
-
我创建了UIActionSheet
,怎么样实现按钮执行删除。- (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]; }
解决方案
调用UIActionSheet delegate
方法:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Delete"])
{
//do your stuff in here
}
}
时间: 2024-10-31 19:53:10