iPhone:UITableView,多次调用didSelectRowAtIndexPath

iPhone:UITableView,多次调用didSelectRowAtIndexPath,iphone,Iphone,我有UITableView…当用户点击行时,另一个屏幕打开。问题是,有时候,我轻触一次,但却多次调用SelectRowatindexpath。如何预防 如何重现这种情况的一个例子是(您甚至可以尝试在本机iPhone设置上重现这种情况): 轻触一行,但不要松开手指 用另一只手按不同顺序从左向右或从右向左滑动下几行(不仅仅是点击,你们应该滑动) 松开手指 您将看到蓝色选择在几行上,并且将打开的屏幕是随机的 更新: 在didSelectRow中,我刚刚启动了新控制器,在viewDidLoad中,同步开

我有UITableView…当用户点击行时,另一个屏幕打开。问题是,有时候,我轻触一次,但却多次调用SelectRowatindexpath。如何预防

如何重现这种情况的一个例子是(您甚至可以尝试在本机iPhone设置上重现这种情况):

  • 轻触一行,但不要松开手指
  • 用另一只手按不同顺序从左向右或从右向左滑动下几行(不仅仅是点击,你们应该滑动)
  • 松开手指
  • 您将看到蓝色选择在几行上,并且将打开的屏幕是随机的

    更新: 在didSelectRow中,我刚刚启动了新控制器,在viewDidLoad中,同步开始。 如果要一步一步地重现我的场景,同步可以启动几次

      - (void)tableView:(UITableView *)tableView 
            didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        SecondViewController *secondViewController =
            [SecondViewController alloc] init];
        [self.navigationController 
            pushViewController:secondViewController animated:YES];
        [secondViewController release];
      }
    

    是的,我发现同样的情况

  • 轻触一行,但不要松开手指
  • 继续轻按并移动手指,直到取消选择该行
  • 按住第一个手指,用另一个手指轻触屏幕几次
  • 松开所有手指
  • 然后您可以看到多次调用了didSelectRowAtIndexPath方法

    我为测试它创建了一个新项目,并使用了以下代码。它被复制在每一个时代

    所以我认为这是iOS SDK的一个bug

    #import "SPViewController.h"
    
    @interface SPViewController ()
    @property (nonatomic, strong) UITableView *tableView;
    @end
    
    @implementation SPViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        [self.view addSubview:self.tableView];
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    
    #pragma mark - UITableViewDataSource
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return 30;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString *cellIdentifier = @"cellIdentifier";
        UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if(cell == nil){
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }
        cell.textLabel.text = [NSString stringWithFormat:@"Test Cell %d", indexPath.row];
        return cell;
    }
    
    #pragma mark - UITableViewDelegate
    
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return 66;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        NSLog(@"%s %@", __FUNCTION__, indexPath);
    }
    
    @end
    

    是的,我发现同样的情况

  • 轻触一行,但不要松开手指
  • 继续轻按并移动手指,直到取消选择该行
  • 按住第一个手指,用另一个手指轻触屏幕几次
  • 松开所有手指
  • 然后您可以看到多次调用了didSelectRowAtIndexPath方法

    我为测试它创建了一个新项目,并使用了以下代码。它被复制在每一个时代

    所以我认为这是iOS SDK的一个bug

    #import "SPViewController.h"
    
    @interface SPViewController ()
    @property (nonatomic, strong) UITableView *tableView;
    @end
    
    @implementation SPViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        [self.view addSubview:self.tableView];
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    
    #pragma mark - UITableViewDataSource
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return 30;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString *cellIdentifier = @"cellIdentifier";
        UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if(cell == nil){
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }
        cell.textLabel.text = [NSString stringWithFormat:@"Test Cell %d", indexPath.row];
        return cell;
    }
    
    #pragma mark - UITableViewDelegate
    
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return 66;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        NSLog(@"%s %@", __FUNCTION__, indexPath);
    }
    
    @end
    

    如果不释放手指,则不会调用didSelectRowAtIndexPath。在它之前调用了另一个委托
    将选择rowatindexpath
    。这些代理不会被重复调用。您可能想发布一些代码来描述您的问题。我相信这是您在代码中犯的错误。您是对的,如果我不释放finger,将不会调用didSelectRowAtIndexPath,但当我释放finger时,它会调用多次。这种方法我没有什么特别之处。我将在一分钟内添加更新,如果您不释放finger,则不会调用
    didSelectRowAtIndexPath
    。在它之前调用了另一个委托
    将选择rowatindexpath
    。这些代理不会被重复调用。您可能想发布一些代码来描述您的问题。我相信这是您在代码中犯的错误。您是对的,如果我不释放finger,将不会调用didSelectRowAtIndexPath,但当我释放finger时,它会调用多次。这种方法我没有什么特别之处。我将在几分钟内添加更新这不是解决方案这不是解决方案