简体   繁体   English

当我在iOS中点击视图时如何关闭TableViewCell中的操作表

[英]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.

相关问题 如何在单击时不关闭ActionSheet单元? - How can I make an ActionSheet cell not dismiss when clicked? 当我点击导航栏时,条形按钮的ios动作表不会消失 - ios actionsheet from bar button not dismissing when i tap on navigation bar Xamarin.ios当在屏幕上点击时,关闭UIAlertController ActionSheet - Xamarin.ios Close UIAlertController ActionSheet when tap on screen iOS如何在任何地方点击UIAlertView? - iOS How to dismiss UIAlertView with one tap anywhere? 当我在tableview中点击一行时,关闭popover - Dismiss the popover when I tap a row in a tableview 在外部点击iOS 8上关闭模式表单表视图 - Dismiss modal form sheet view on outside tap iOS 8 在 UIAlertController 外部点击时如何关闭 UIAlertController? - How to dismiss UIAlertController when tap outside the UIAlertController? iOS-当在UIView上的任意位置轻按时,如何从navigationItem.searchController关闭键盘? - iOS - How to dismiss keyboard from the navigationItem.searchController when tap anywhere on the UIView? SwiftUI ActionSheet 在计时器运行时不会关闭 - SwiftUI ActionSheet does not dismiss when timer is running 当单元格处于焦点时,iOS将视图放在TableViewCell上 - iOS Place a View on a TableViewCell when cell is in focus
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM