【发布时间】:2013-11-19 14:53:56
【问题描述】:
我的 UITableView 有问题。
方法“didSelectRowAtIndexPath”不会被调用,直到我在该行上停留最少 2 秒。如果我只是像普通人那样在单元格上单击一次以选择它,则不会发生任何事情:没有调用 didSelectRowAtIndexPath。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellWithSelection" forIndexPath:indexPath];
NSDictionary *player = _objects[indexPath.row];
cell.textLabel.attributedText = [TCUtilities defaultAttributedStringWithString:[player objectForKey:@"personalName"] AndSize:DEFAULT_SIZE AndColor:DEFAULT_TEXT_COLOR];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setBackgroundColor:[UIColor grayColor]];
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setBackgroundColor:[UIColor clearColor]];
[cell setAccessoryType:UITableViewCellAccessoryNone];
}
【问题讨论】:
-
我看到你正在使用
dequeueReusableCellWithIdentifier:。在您的界面构建器中如何设计具有重用标识符CellWithSelection的单元格?此外,您的视图上有手势识别器吗? -
谢谢zbMax!我在 viewDidLoad 中忘记了这个手势识别器。它是固定的:)
标签: ios uitableview didselectrowatindexpath