Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.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 UITapGestureRecognitor根本不工作_Ios_Objective C_Uitableview - Fatal编程技术网

Ios UITapGestureRecognitor根本不工作

Ios UITapGestureRecognitor根本不工作,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我的任务是在已有的iPad/iPhone应用程序中添加一个音频播放器。在过去的两天里,我一直在努力弄清楚为什么我不能用一个简单的敲击手势来工作。我在互联网上搜遍了都没有用。我知道有几个问题像这样已经存在了,但我仍然非常困惑。请帮忙!我正在处理的区域位于带有单元格的tableview中。我正在将一个子视图添加到一些单元格中,这些单元格从一个名为“背景”的视图开始,并将其他视图添加到其中。我添加了一个包含播放按钮的简单UIView。我的“play button”视图是通过如下方法构建的: -(UIV

我的任务是在已有的iPad/iPhone应用程序中添加一个音频播放器。在过去的两天里,我一直在努力弄清楚为什么我不能用一个简单的敲击手势来工作。我在互联网上搜遍了都没有用。我知道有几个问题像这样已经存在了,但我仍然非常困惑。请帮忙!我正在处理的区域位于带有单元格的tableview中。我正在将一个子视图添加到一些单元格中,这些单元格从一个名为“背景”的视图开始,并将其他视图添加到其中。我添加了一个包含播放按钮的简单UIView。我的“play button”视图是通过如下方法构建的:

-(UIView*) messagePlayerImageViewForMessage:(LAZMessage*) message {
UIView* returnView = [[UIView alloc] initWithFrame:CGRectZero];
UIImageView* playButtonImageView = [[UIImageView alloc] init];
[returnView addSubview:playButtonImageView];
playButtonImageView.tag = TAG_CELL_PLAY_IMAGE_VIEW;

if ([self stringForMessageRecordingId:message]) {
    UIImage* playButton = [UIImage imageNamed:@"play"];
    [playButtonImageView setImage:playButton];
    [playButtonImageView setFrame:CGRectMake(0, 0, playButton.size.width/2, playButton.size.height/2)];

    [returnView setFrame:CGRectMake(0, 0, playButtonImageView.frame.size.width, playButtonImageView.frame.size.height)];
}
returnView.tag = TAG_CELL_MESSAGE_PLAYER_VIEW;
return returnView;
}
创建此子视图后,我将其附加到单元视图中,并尝试像这样添加手势识别器

UIView* messagePlayerView = [self messagePlayerImageViewForMessage:message];
messagePlayerView.tag = TAG_CELL_MESSAGE_PLAYER_VIEW;
messagePlayerView.userInteractionEnabled = YES;
[background addSubview:messagePlayerView];

UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[messagePlayerView addGestureRecognizer:tapGesture];
tapGesture.cancelsTouchesInView = NO;
tapGesture.delegate = self;
相应的抽头功能为

-(void) handleTap:(UITapGestureRecognizer*) tapGestureRecognizer{
    NSLog(@"hi");
}
在ViewController.h中,类被声明为,我在ViewController.m文件中添加了以下代码

-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}
没有.xib,这都是通过编程完成的

有什么想法吗?关于如何开始调试这个有什么想法吗

编辑:


我将UITapGestureRecognitor添加到UITableView,这将注册一个点击。有人知道如何让点击流到我想要的特定子视图吗。

你需要为
UImageView设置
userIntreactionEnable
,试试这个

-(UIView*) messagePlayerImageViewForMessage:(LAZMessage*) message {
UIView* returnView = [[UIView alloc] initWithFrame:CGRectZero];
UIImageView* playButtonImageView = [[UIImageView alloc] init];
[returnView addSubview:playButtonImageView];
playButtonImageView.userInteractionEnabled = YES;
playButtonImageView.tag = TAG_CELL_PLAY_IMAGE_VIEW;

if ([self stringForMessageRecordingId:message]) {
    UIImage* playButton = [UIImage imageNamed:@"play"];
    [playButtonImageView setImage:playButton];
    [playButtonImageView setFrame:CGRectMake(0, 0, playButton.size.width/2, playButton.size.height/2)];

    [returnView setFrame:CGRectMake(0, 0, playButtonImageView.frame.size.width, playButtonImageView.frame.size.height)];
}
returnView.tag = TAG_CELL_MESSAGE_PLAYER_VIEW;
return returnView;
}

表视图的触摸事件可能会取消UIView手势的触摸事件,您可能必须禁用表视图的行选择

这是打字错误吗?UITapGestureRecognizer*点击手势=[[UITapGestureRecognizer alloc];initWithTarget:self action:@selector(handleTap:)];是的,对不起,没有多余的分号。我的代码中的行如下所示:UITapGestureRecognitzer*Tap手势=[[UITapGestureRecognitzer alloc]initWithTarget:self-action:@selector(handleTap:)];嘿,“背景”是什么样的观点?UIImageView或UIView?声明如下,UIView*背景;这是在-(UITableViewCell)tableView:(UITableView*)tableView CellForRowatineXpath:(NSIndexPath*)indexPath中声明的。该函数将其他几个子视图添加到背景中,然后将背景添加到单元中,该单元属于UITableViewCell。我建议您创建一个自定义单元类。使用标记视图只适用于非常简单的单元格,而您的视图听起来不像一个简单的单元格。请创建自定义子类。另外,您是否正在
CellForRowatineXpath:
中添加这些视图/手势识别器?您知道表视图单元格被重用了吗?谢谢您的回复,不幸的是仍然没有。我甚至试着将该属性添加到returnView中,以获得更好的效果——同样的效果。对于如何验证是否发生这种情况,您有什么建议吗?请尝试在cellForRowAtIndexPath中的tableviewcell中设置、选择StyleNone,并检查guesture事件是否为firedI added cell。选择Style=UITableViewCellSelectionStyleNone;在cellForRowAtIndexPath中的单元格声明之后。这似乎对桌子没有任何影响(好或坏)。我认为这可能是问题所在。我尝试将我的UITapGestureRecognitor添加到UITableView,整个视图都注册了该点击。现在,如果我能想出如何让点击到更小的播放按钮。