0

这是一个菜鸟问题。我创建了 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];
}
4

3 回答 3

2

尝试调用UIActionSheet委托方法

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

    NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];

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

     }

}
于 2013-02-01T17:59:36.567 回答
1

你的类必须符合UIActionSheetDelegate协议。

然后覆盖该actionSheet:clickedButtonAtIndex:方法,评估单击的按钮并采取相应措施。

请参阅此处了解更多信息。

于 2013-02-01T17:55:18.340 回答
0

只是添加到其他两个解决方案,您可以- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event像这样在您的方法中添加委托(假设您的类实现UIActionSheetDelegate协议):

shakeActionSheet.delegate = self;
于 2013-02-01T18:26:55.360 回答