【问题标题】:Confirm UIGestureRecognizer?确认 UIGestureRecognizer?
【发布时间】:2013-02-27 04:08:39
【问题描述】:

当我使用UIGestureRecognizer时,例如,当用户向右滑动时,我想有一个UIAlertView询问他是否真的要提交向右滑动的动作。

我尝试过这样做,但没有成功。

【问题讨论】:

标签: iphone ios uigesturerecognizer gesture


【解决方案1】:

UIGestureRecogniser 事件方法中,创建一个带有适当标题/消息的UIAlertView

UIAlertView 的代理设置为self,在alertView:didDismissWithButtonIndex: 中,您可以根据用户点击的内容执行或不执行操作。

【讨论】:

  • 看到我的问题是当检测到 UIAlertView 中按下了哪个按钮时,如何访问 UIGestureRecognizer 状态属性?您能否发布这部分的示例代码?
【解决方案2】:

这样做,

UISwipeGestureRecognizer *gesture1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeRight:)];
gesture1.direction = UISwipeGestureRecognizerDirectionRight;
[yourView addGestureRecognizer:gesture1];

在Action方法中,

-(void)didSwipeLeft:(UIGestureRecognizer *)gestureRecognizer {
    UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Are you sure to commit with its action" delegate:self cancelButtonTitle:CKString(@"NO") otherButtonTitles:CKString(@"YES"),nil];
    [Alert show];
    Alert.tag=222;
    Alert.delegate=self;
    [Alert release];
}

在 AlertView 委托中

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    if(alertView.tag==222) {
        if(buttonIndex==1)
        {
            //// Yes condition
        } else {
           ///// No condition
        }
    }
}

【讨论】:

  • 好的,我明白了。因此,您甚至不必为 UIGestureRecognizer 属性而烦恼。基于标签。怎么会是 222 然后是 111?
  • 但是等等,我的委托中有这个:[priceArray removeObjectAtIndex:indexPath.row]; [nameArray removeObjectAtIndex:indexPath.row]; [mainTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  • 如何从代理访问 indexPath?
  • 是的,我正在从 TableView 中删除行。
  • 为什么不呢?我正在确认删除?
猜你喜欢
  • 2011-05-03
  • 2015-04-25
  • 2012-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多