Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在UITapGestureRecognizer中的@selector中传递参数?_Iphone_Xcode_Selector - Fatal编程技术网

Iphone 如何在UITapGestureRecognizer中的@selector中传递参数?

Iphone 如何在UITapGestureRecognizer中的@selector中传递参数?,iphone,xcode,selector,Iphone,Xcode,Selector,我的“表格标题视图”部分中有以下内容: UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sectionHeaderTapped:)]; 我想在方法sectionHeaderTapped中传递节号,以便识别哪个节被点击 我的方法实现如下所示: -(void)sectionHeaderTapped:(NSInteger)secti

我的“表格标题视图”部分中有以下内容:

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sectionHeaderTapped:)];
我想在方法
sectionHeaderTapped
中传递节号,以便识别哪个节被点击

我的方法实现如下所示:

-(void)sectionHeaderTapped:(NSInteger)sectionValue {
    NSLog(@"the section header is tapped ");    
}

如何实现这一点?

另一种选择:您可以在
tableHeaderView
上添加
UIButton
,然后单击按钮。

方法
sectionHeaderTapped
应具有以下签名之一:

- (void)sectionHeaderTapped:(UITapGestureRecognizer *)sender;
- (void)sectionHeaderTapped;
你必须用抽头的坐标算出被抽头的单元格

-(void)sectionHeaderTapped:(UITapGestureRecognizer *)gestureRecognizer
{
    CGPoint tapLocation = [gestureRecognizer locationInView:self.tableView];
    NSIndexPath *tapIndexPath = [self.tableView indexPathForRowAtPoint:tapLocation];
    UITableViewCell* tappedCell = [self.tableView cellForRowAtIndexPath:tapIndexPath];
}
您可能可以使用该方法获取节标题。但是,将不同的手势识别器附加到每个节标题可能更容易

- (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    // ...
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sectionHeaderTapped:)];
    [headerView addGestureRecognizer:tapGesture];
    return headerView;
}
然后

-(void)sectionHeaderTapped:(UITapGestureRecognizer *)gestureRecognizer
{
    UIView *headerView = gestureRecognizer.view;
    // ...
}

是的,我在每个部分都使用了不同的手势,不是最好的方式,而是更简单的方式。。。谢谢