[英]How to dismiss the actionsheet in tableviewcell when i tap on the view in ios
Here is my Code.Am very new to Xcode.When i tap on tableview cell am getting UIActionSheet.To dismiss UIActionSheet i used UITapGestureRecognizer.It's not Working for me. 这是我的Code.Xcode的新手,当我点击tableview单元格时会得到UIActionSheet。要关闭UIActionSheet,我使用了UITapGestureRecognizer。它对我不起作用。
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath];
UILabel *lbl = (UILabel *)[cell.contentView viewWithTag:2];
NSLog(@"cell text label =%@",lbl.text);
_StoreNameobj = lbl.text;
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Store Maintenance Action"
delegate:self
cancelButtonTitle:cancelTitle
destructiveButtonTitle:nil
otherButtonTitles:@"Show Store Details",@"Navigate to Store",@"Edit Store Nickname",@"Delete Store", nil];
actionSheet.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOut:)];
[lbl addGestureRecognizer:tapGesture];
[cell.contentView addSubview:lbl];
}
- (void)tapOut{
//dismiss the action sheet here
[actionSheet removeFromSuperview];
}
Any Help is Appreciable.Thanks in Advance! 任何帮助都是可以的。在此先感谢!
I think you not need to manually remove the actionsheet. 我认为您不需要手动删除操作表。 By default actionsheet resigns on click. 默认情况下,动作表会在点击时退出。 there is no need to take tab gesture i think. 我认为没有必要采取跳格手势。
Show actionsheet like, 显示动作表,
[actionSheet showInView:self.view];
so when you clik on any button it will dissmiss automatically 因此,当您按下任何按钮时,它将自动关闭
To view UIActionSheet on UITableViewCell apply this code 要在UITableViewCell上查看UIActionSheet,请应用此代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Your Title:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:
@"button title1", nil];
[popup show];
}
add TapGesture 添加TapGesture
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UITapGestureRecognizer *tapp = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(HideActionSheet:)];
[tapp setNumberOfTapsRequired:1];
tapp.cancelsTouchesInView = NO;
[self.view.window tapp];
[tapp release];
}
HideActionSheet code: HideActionSheet代码:
- (void) HideActionSheet:(UITapGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded)
{
CGPoint location = [sender locationInView:nil];
if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil])
{
[self.view.window removeGestureRecognizer:sender];
[self dismissModalViewControllerAnimated:YES];
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.