原問題描述:
大家好,請教一個關於UIGestureRecognizer的問題。
比如我需要在用戶在操作之後,用UIAlertView來確認提交動作,我試過一些方法都沒成功。
解決方案:
這樣:
[java]
UISwipeGestureRecognizer *gesture1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeRight:)];
gesture1.direction = UISwipeGestureRecognizerDirectionRight;
[yourView addGestureRecognizer:gesture1];
在Action方法中:
[java]
-(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 Delegate
[java]
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(alertView.tag==222) {
if(buttonIndex==1)
{
//// Yes condition
} else {
///// No condition
}
}
}