【问题标题】:When I tap the first cell in my tableview didSelectRowAtIndexPath is not triggered当我点击表格视图中的第一个单元格时,没有触发 didSelectRowAtIndexPath
【发布时间】:2009-09-28 13:55:47
【问题描述】:

当我点击表格视图中的第一个单元格时,didSelectRowAtIndexPath 没有被触发...有没有人看起来和/或知道为什么会发生这种情况?我表中的所有其他单元格都可以正常工作,我在didSelectRowAtIndexPath 的代码中放置了一个断点,如果点击第一个单元格,应用程序不会进入该代码,但如果点击任何其他单元格,它将进入代码。 这是一些代码:

    - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger row = 0;
    return row;
}

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger row = [indexPath row];
    if (row == 0)
        return nil;

    return indexPath;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //NSUInteger row = [indexPath row];
    //NSString *rowValue = [poolListData objectAtIndex:row];

    int newRow = [indexPath row];
    int oldRow = [lastIndexPathForPoolList row];

    if (newRow != oldRow)
    {
        UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;

        UITableViewCell *oldCell = [tableView cellForRowAtIndexPath: lastIndexPathForPoolList]; 
        oldCell.accessoryType = UITableViewCellAccessoryNone;

        lastIndexPathForPoolList = indexPath;   
    }

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (NSInteger)tableViewForDelete:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [poolListData count];
}

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

    static NSString *DeleteMeCellIdentifier = @"DeleteMeCellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DeleteMeCellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:DeleteMeCellIdentifier] autorelease];
    }

    NSInteger row = [indexPath row];
    cell.text = [self.poolListData objectAtIndex:row];
    return cell;
}

#pragma mark -
#pragma mark Table View Delegate Methods

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{   
    NSUInteger row = [indexPath row];
    [self.poolListData removeObjectAtIndex:row];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

感谢您的宝贵时间以及您能给我的任何帮助!

【问题讨论】:

  • 对不起,一团糟...我似乎无法正确粘贴代码。
  • 为你更正了。 lastindexpathforpoollist 初始化程序在哪里?
  • 你设置了 tableview.delegate 吗?
  • 我有 lastIndexPathForPoolList 在委托 NSIndexPath *lastIndexPathForPoolList; @property (nonatomic, 保留) NSIndexPath *lastIndexPathForPoolList;但我没有初始化它(哎呀)
  • 哪里是初始化 lastIndexPathForPoolList 的最佳位置?

标签: iphone cell tableview didselectrowatindexpath


【解决方案1】:

我认为您在第一行的 willSelectRowForIndexPath 中返回 nil。这将阻止该行被选中。

【讨论】:

  • 到达那里!!!我把它拿出来了,现在我可以选择第一行,但只有在我先选择任何其他行之后!谢谢!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-02
  • 1970-01-01
  • 2018-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多