相关疑难解决方法(0)

UIGestureRecognizer和UITableViewCell问题

我在这样的方法中附加一个UISwipeGestureRecognizera :UITableViewCellcellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
        gesture.direction = UISwipeGestureRecognizerDirectionRight;
        [cell.contentView addGestureRecognizer:gesture];
        [gesture release];
    }
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

但是,该didSwipe方法在成功滑动时始终被调用两次.我最初认为这是因为手势开始和结束,但如果我注销gestureRecognizer本身,它们都处于"结束"状态:

-(void)didSwipe:(UIGestureRecognizer *)gestureRecognizer {

    NSLog(@"did swipe called %@", gestureRecognizer);
}
Run Code Online (Sandbox Code Playgroud)

安慰:

2011-01-05 12:57:43.478 App[20752:207] did swipe called <UISwipeGestureRecognizer: 0x5982fa0; state = Ended; view = <UITableViewCellContentView …
Run Code Online (Sandbox Code Playgroud)

iphone uitableview ipad uigesturerecognizer ios

44
推荐指数
1
解决办法
3万
查看次数

标签 统计

ios ×1

ipad ×1

iphone ×1

uigesturerecognizer ×1

uitableview ×1