我有一个自定义的UITableview
,它被划分为几个部分,我已经实现了UISwipeGestureRecognizer
。当我滑动我的表格视图单元格时,出现UIButton
。我现在面临的问题是当我滑动第一个表格视图单元格时,连续部分中的另一个单元格也会识别滑动手势。我无法找到如何在没有其他部分的其他单元格被滑动的情况下轻扫特定部分的单元格。如何在一个部分的特定行中滑动tableviewcell
我只想刷卡,我不想删除/插入或添加复选标记。
UPDATE ....这是我customCell.m 泰伯维= customTableView
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
self.backgroundColor = [UIColor clearColor];
self.contentView.backgroundColor = [UIColor clearColor];
self.symptomCellImageView.contentMode=UIViewContentModeScaleToFill;
swipeButton = [[UIButton alloc]init];
swipeButton .frame = CGRectMake(220.0, 8.0, 30.0, 30.0);
swipeButton .hidden = NO;
}
在我MainViewController.m
-(void)viewDidLoad
{
symptomSwipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandleLeft)];
symptomSwipeLeft .numberOfTouchesRequired = 1;
symptomSwipeLeft .direction = UISwipeGestureRecognizerDirectionLeft;
[customTableView addGestureRecognizer:symptomSwipeLeft];
[self addGestureRecognizer:symptomSwipeRight];
symptomSwipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandleRight)];
symptomSwipeRight.numberOfTouchesRequired = 1;
symptomSwipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[customTableView addGestureRecognizer:symptomSwipeRight];
[self addGestureRecognizer:symptomSwipeRight];
}
- (void)swipeHandleLeft:(UISwipeGestureRecognizer *)aSwipeGestureRecognizer
{
CGPoint location = [aSwipeGestureRecognizer locationInView:customTableView ];
NSIndexPath * indexPath = [customTableView indexPathForRowAtPoint:location];
if(indexPath)
{
UITableViewCell * cell = (UITableViewCell *)[customTableView cellForRowAtIndexPath:indexPath];
[cell.swipeButton addTarget:self action:@selector(secondPageButton:) forControlEvents:UIControlEventTouchUpInside];
}
}
- (void)swipeHandleRight:(UISwipeGestureRecognizer *)aSwipeGestureRecognizer
{
CGPoint location = [aSwipeGestureRecognizer locationInView:customTableView ];
NSIndexPath * indexPath = [customTableViewindexPathForRowAtPoint:location];
if(indexPath)
{
UITableViewCell * cell = (UITableViewCell *)[customTableView cellForRowAtIndexPath:indexPath];
[cell.swipeButton addTarget:self action:@selector(secondPageButton:) forControlEvents:UIControlEventTouchUpInside];
}
}
..不应该叫[单元格。swipeButton addTarget:自我行动:@选择(intoView :) forControlEvents:UIControlEventTouchUpInside]中的cellForRowAtIndexPath 和标签应的cellForRowAtIndexPath做正确的 – raptor 2013-04-22 17:15:11
我的代码将你的'UISwipeGestureRecognizer',给你的用户刷卡确切的细胞。从那里,你可以调用你喜欢的任何方法。因此,如果你想要出现滑动按钮,只需调用'cell.swipeButton.hidden =!cell.swipeButton.hidden'(这将使按钮隐藏,如果它隐藏或反之亦然)。你甚至可以调用一个自定义的单元格方法来使按钮变成动画!根本不需要'.tag'属性! – msgambel 2013-04-22 17:21:57
谢谢:)...我会研究它..只是再一件事情,如果我在第一节中刷单元格,然后单元格在其他部分不会被刷卡正确 – raptor 2013-04-22 17:23:20