Ios 向左滑动单元格时,在Alertview中显示行数。界面生成器中添加的滑动手势

Ios 向左滑动单元格时,在Alertview中显示行数。界面生成器中添加的滑动手势,ios,objective-c,Ios,Objective C,我想在alertview中显示正在刷卡的单元格的行号。 我的问题是,我无法获取正在刷卡的行号,它始终显示“0” 我已经用界面生成器添加了滑动手势 我的.h文件 @property (strong, nonatomic) IBOutlet UISwipeGestureRecognizer *gestureSwipeLeft; @property (nonatomic, retain) NSIndexPath * indexPath; @property (nonatomic, assign) in

我想在alertview中显示正在刷卡的单元格的行号。 我的问题是,我无法获取正在刷卡的行号,它始终显示“0”

我已经用界面生成器添加了滑动手势

我的.h文件

@property (strong, nonatomic) IBOutlet UISwipeGestureRecognizer *gestureSwipeLeft;
@property (nonatomic, retain) NSIndexPath * indexPath;
@property (nonatomic, assign) int test;
我的.m文件

- (IBAction)handleSwipeLeft:(UISwipeGestureRecognizer *)sender{

UIAlertView *getRow = [[UIAlertView alloc]initWithTitle:@"RowNumberSwiped" message:[NSString stringWithFormat:@"%i", _test] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

[getRow show];
}

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
_test = self.indexPath.row;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myBasicCell"];

thingToDoDoc *things = [self.things objectAtIndex:indexPath.row];

UILabel *lblTitle = (UILabel *)[cell viewWithTag:100];
lblTitle.text = things.data.title;

UIImageView *ratingImageView = (UIImageView *)[cell viewWithTag:101];
//  _lblTitle.text = things.data.title;
if (things.data.isDone == 2) {
    ratingImageView.image = [UIImage imageNamed:@"checkmark.png"];
}

return cell;
}

正如我在上面的评论中提到的,每次调用CellForRowatineXpath时,测试都会被覆盖,请在GestureRecognitor回调中尝试类似的操作

-(void)cellSwipe:(UISwipeGestureRecognizer *)gesture
{
    CGPoint location = [gesture locationInView:tableView];
    NSIndexPath *swipedIndexPath = [tableView indexPathForRowAtPoint:location];
    UITableViewCell *swipedCell  = [tableView cellForRowAtIndexPath:swipedIndexPath];

    //Your own code...
}

您不需要使用_testint变量来实现您想要实现的目标。根据tableView:cellForRowAtIndexPath中的当前代码,每次调用此方法时,您都会将新的indexath.row值分配给_test(_test每次都会被覆盖)。甚至您也没有在上述代码的任何地方设置self.indepath的值。您必须获取当前扫描行的索引,以便以不同的方式显示在Alertview中。请参阅(并将该方法替换为)以下代码:

- (IBAction)handleSwipeLeft:(UISwipeGestureRecognizer *)sender{

    UIAlertView *getRow = [[UIAlertView alloc]initWithTitle:@"RowNumberSwiped" message:[NSString stringWithFormat:@"%i", [yourTableView indexPathForRowAtPoint:[self.gestureSwipeLeft locationInView:yourTableView]].row] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [getRow show];
}

希望这对您有所帮助。

cellforrowatinexpath
在tableView中每行调用一次,您的覆盖测试在每次显示一行时都会执行。这是正确的。忘了!您有我的问题的解决方案吗?添加了一个答案,如果它解决了您的问题,请不要忘记向上投票/标记顶部答案,如果没有,请在我的GesterRecognizer回调上留下评论?我应该把新代码放在哪里?@user3100927当检测到刷卡时,GestureRecognitor回调就是您运行的方法。您使用的
handlesweepleft
我在这里给出的方法签名几乎相同。然后在
handlesweepleft
中,您将获得样本中两个变量的
indepath
单元格