我有一個自定義的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