当添加UITapGestureRecognizer处理程序方法时,为什么TableView委托方法停止工作

问题描述 投票:0回答:1

我有一个UITableViewController,带有一个用于弹出框的xib。在尝试向视图中添加UITapGestureRecognizer之前,它一直运行良好。通过将表视图作为插座集合连接到UITapGestureRecognizer的情况,当用户点击表中的项目时,将触发点击处理程序,但不再激活表视图的didSelectRowAtIndexPath方法。

我想做的是获取水龙头的位置,这样我就可以将下一个弹出窗口扔到一个合理的位置。也许有更好的方法可以做到这一点?

这里是我的表格视图接线图...

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9pbFVMNC5naWYifQ==” alt =“在此处输入图像描述”>

这里是识别器的接线...

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS81S1dpcy5naWYifQ==” alt =“在此处输入图像描述”>

这里是我的拍子处理程序,当您选择一个项目时,它会被连接好,并能正常工作。

- (IBAction)tapHandler:(UITapGestureRecognizer *)sender {
    if (sender.state == UIGestureRecognizerStateEnded) {
        tapPosition = [sender locationInView:self.view];
    }
}

这里是didselectrowAtIndexPath方法。除非我连接了tapGestureRecognizer,否则射击效果很好。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   [myPO dismissPopoverAnimated:YES];
   [self.delegate popupListItemSelected:self withItemRow:indexPath.row item:[listItems objectAtIndex:indexPath.row]];
}

这里是我的界面文件中适用的部分。所有对象都是合成的...

#import <UIKit/UIKit.h>

@protocol PopUpListViewControllerDelegate;

@interface PopUpListViewController : UITableViewController {
   id<PopUpListViewControllerDelegate> delegate;
   IBOutlet UITableView *poupListTableView;
   UIPopoverController *myPO;
   NSMutableArray *listItems;
   IBOutlet UITapGestureRecognizer *tapRecognizer;   
}
@property (assign) id<PopUpListViewControllerDelegate> delegate;
@property (retain, nonatomic) IBOutlet UITableView *poupListTableView;
@property (retain, nonatomic) NSMutableArray *listItems;

@property (retain, nonatomic) IBOutlet UITapGestureRecognizer *tapRecognizer;
- (IBAction)tapHandler:(UITapGestureRecognizer *)sender;
- (CGPoint)getTappedPosition;

@end

我有一个UITableViewController,带有一个用于弹出框的xib。在尝试向视图中添加UITapGestureRecognizer之前,它一直运行良好。将表格视图连接到...

ios uitableview uigesturerecognizer
1个回答
1
投票

一种选择是使用点击处理程序中的CGPoint并使用UITableView方法找到相应的行:

© www.soinside.com 2019 - 2024. All rights reserved.