UITableView没有正确选择

Nic*_*ick 4 objective-c uitableview

我正在开发一个iPhone应用程序,我有一个UITableView,它通过URL填充XML feed.

比如说,填充了三个单元格.

如果我点击第一个单元格没有任何反应,但是如果我点击第二个或第三个单元格,它会将我带到与第一个单元格相关的第二个屏幕,而其他单元格也会发生同样的情况 - 点击它没有任何东西,点击另一个单元格它将我带到前一个选定的第二个屏幕.

我从来没有遇到过这种情况而且很困惑.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                              reuseIdentifier:@"UITableViewCell"];
    }

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    LocationsItem *atm = [[locations atms] objectAtIndex:[indexPath row]];
    [[cell textLabel] setText:[atm atmName]];

    float distance = [[atm atmDistance] floatValue];
    NSString *distanceString = [NSString stringWithFormat:@"%0.2f miles from current location", distance];
    [[cell detailTextLabel] setText:distanceString];

    return cell;
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    LocationsItem *atm = [[locations atms] objectAtIndex:[indexPath row]];

    ATMDetailsController *detailsController = [[ATMDetailsController alloc] init];

    [detailsController setCurrentATM: atm];

    [[self navigationController] pushViewController:detailsController animated:YES];

}
Run Code Online (Sandbox Code Playgroud)

谢谢,尼克

Tro*_*roy 9

你是在自问自答.问题是你使用tableView:deselectRowAtIndexPath:而不是tableView:didSelectRowAtIndexPath:

值得注意的是,这是来自词典deselect之前的不幸事实,did因此,xcode通常很棒的代码完成会让你感到惊讶!

现在去拿那些调试时间回来!