Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.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
Ios 向现有表视图节标题动态添加手势_Ios_Iphone_Objective C_Uitableview - Fatal编程技术网

Ios 向现有表视图节标题动态添加手势

Ios 向现有表视图节标题动态添加手势,ios,iphone,objective-c,uitableview,Ios,Iphone,Objective C,Uitableview,我正在尝试使用下面的代码向我的表视图部分标题添加一个点击手势。但它不会在返回的视图中嵌入手势。我做错了什么?非常感谢你的帮助 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *view = [tableView headerViewForSection:section]; UITapGestureRecognizer *single

我正在尝试使用下面的代码向我的表视图部分标题添加一个点击手势。但它不会在返回的视图中嵌入手势。我做错了什么?非常感谢你的帮助

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

    UIView *view = [tableView headerViewForSection:section];

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissKeyBoard)];
    [view addGestureRecognizer:singleTap];


    return view;
}

尝试将代理设置为手势识别器,以便它与滚动视图(表格视图)的手势一起被识别:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}
如下所示设置代理:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissKeyBoard)];
singleTap.delegate = self;
[view addGestureRecognizer:singleTap];

您还需要确保只设置一次手势,因为每次标题出现/重新出现在屏幕上时都会调用tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)节。按照您的方式,您将在标题视图中使用多个手势识别器。

感谢Edwin的快速响应,但我担心这并没有解决问题。但是,如果我尝试创建如下所示的视图,并指定手势,效果会很好。UIView*view=[[UIView alloc]init];唯一的问题是,当我尝试分配我现有的标题节时,它不起作用。在这种情况下,我认为您的问题是[tableView HeaderServiceWforSection:section]返回零。您首先需要注册一个类或nib来处理is。看这上帝。。非常感谢埃德温。这正是问题所在。它返回null。我需要注册笔尖。再次感谢。