2012-02-11 63 views
4

我正在开发一个iPhone应用程序,其中有一个UITableView,它正在通过URL填充XML feed。UITableView没有正确选择

举例说,三个单元格被填充。

如果我点击第一个单元格没有任何反应,但是如果我点击第二个或第三个单元格,它将把我带到与第一个单元格相关的第二个屏幕,并且与其他单元格相同 - ,点击另一个,它会将我带到上一个选中的第二个屏幕。

我从来没有发生过这种情况,而且相当困惑。

- (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]; 

} 

感谢, 尼克

+3

任何示例代码? – TigerCoding 2012-02-11 20:08:08

+1

请发布您的cellForRowAtIndexPath:代码 – Rayfleck 2012-02-11 20:10:29

+1

听起来像您在'tableView:didSelectRowAtIndexPath:'中的索引是关闭的,但没有看到一些相关的代码,这是不可能的。 – 2012-02-11 20:11:34

回答

9

你回答了你自己的问题。问题是,你用tableView:deselectRowAtIndexPath:代替tableView:didSelectRowAtIndexPath:

值得注意的是,这是不幸的事实deselect进来字典did之前,因此,Xcode的正常真棒代码完成hinks你!

现在去调试回来的小时!

+0

我也有同样的问题。浪费了一个小时,试图弄清楚发生了什么。需要更多地关注自动完成和语法,哈哈。 – Tander 2014-01-07 07:31:01