【问题标题】:Need to stay clicked on row to select it需要保持点击行来选择它
【发布时间】: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


【解决方案1】:

感谢 zbMax。 我在 viewDidLoad 方法中实现了一个手势识别器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-30
    • 2023-03-27
    • 1970-01-01
    • 2017-07-19
    • 2017-08-13
    • 1970-01-01
    相关资源
    最近更新 更多