Iphone 使用UIPangestureRecognitor拖动后,必须轻触两次才能选择UITableViewCell
我有一个名为Iphone 使用UIPangestureRecognitor拖动后,必须轻触两次才能选择UITableViewCell,iphone,uitableview,uigesturerecognizer,Iphone,Uitableview,Uigesturerecognizer,我有一个名为SubViewController.h的小型320x144viewcontroller,其中有一个UITableView,有3个单元格和一个部分。我通过CALayer,使tableView不可滚动,并在tableView后面添加了一些阴影效果 在另一个名为MainViewController.m的viewcontroller中,我将SubViewController.h作为子视图添加到此MainViewController。使用ui搜索识别器我已成功地将SubViewContolle
SubViewController.h
的小型320x144
viewcontroller,其中有一个UITableView,有3个单元格和一个部分。我通过CALayer
,使tableView不可滚动,并在tableView后面添加了一些阴影效果
在另一个名为MainViewController.m的viewcontroller中,我将SubViewController.h
作为子视图添加到此MainViewController
。使用ui搜索识别器
我已成功地将SubViewContoller拖动到我想要的任何位置
我使用UIBarButtonItem
使此子视图可见。在子视图的tableView中选择一个单元格后,我通过一些动画使它从主视图中消失
一切正常
但当我拖动子视图,然后尝试选择一个单元格时,我必须轻触该单元格两次。在第一次点击中,除了单元格变为蓝色(就像在tableView中选择单元格时通常发生的情况)之外,实际上什么都不会发生,但不会隐藏。如果我再次点击,它就会隐藏起来
无需拖动子视图,我只需一次触摸即可选择一个单元格,视图也将隐藏
我已经编写了在子视图的didselectrowatinexpath:
方法中隐藏子视图的代码。我已经检查过,在拖动子视图后第一次选择时,不会调用此方法。但在第二次点击或触摸时,会调用此方法。如果用户再次移动子视图,同样的问题也会发生
当然,子视图的某些属性在拖动后发生了更改,我无法理解。首先,当您希望显示子视图时,即单击UIBarButtonim:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
NSUInteger tapCount = [touch tapCount];
switch (tapCount) {
case 1:
[self performSelector:@selector(singleTapMethod) withObject:nil afterDelay:.4];
break;
case 2:
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTapMethod) object:nil];
[self performSelector:@selector(doubleTapMethod) withObject:nil afterDelay:.4];
break;
. . .
}
-(IBAction)buttonClick
{
//setup ur view dynamically as you like//
PSview=[[UIView alloc]initWithFrame:CGRectMake(5, 5, 310,450)];
PSview.backgroundColor=[UIColor blackColor];
PSview.alpha=0.8;
[PSview.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[PSview.layer setBorderWidth: 3.0];
PSview.contentMode=UIViewContentModeScaleAspectFill;
PSview.clipsToBounds=YES;
[PSview.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[PSview.layer setBorderWidth: 3.0];
[PSview addSubview:subView];
[self.view addSubview:PSview];
}
随后:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//since there are two tables in one view, you can differentiate them using if()
if(tableView==subView)
{
// ...ur code . ..
// write your code what needs to happen when you click a row of your subView.
[PSview removeFromSuperview];
}
if(tableView==mainView)
{
// write your code , what happens when user clicks row of the main table
}
}
这不是我所期望的。我确信我必须在演讲结束时写点东西。请你详细说明你的观点好吗??