iPhone:UITableView,多次调用didSelectRowAtIndexPath
我有UITableView…当用户点击行时,另一个屏幕打开。问题是,有时候,我轻触一次,但却多次调用SelectRowatindexpath。如何预防 如何重现这种情况的一个例子是(您甚至可以尝试在本机iPhone设置上重现这种情况):iPhone:UITableView,多次调用didSelectRowAtIndexPath,iphone,Iphone,我有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];
}
是的,我发现同样的情况
#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
是的,我发现同样的情况
#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时,它会调用多次。这种方法我没有什么特别之处。我将在几分钟内添加更新这不是解决方案这不是解决方案