我正在开发一个iPhone应用程序,我有一个UITableView,它通过URL填充XML提要。
比如说,填充了三个单元格。
如果我点击第一个单元格没有任何反应,但是如果我点击第二个或第三个单元格,它会将我带到与第一个单元格相关的第二个屏幕,而其他单元格也会发生同样的情况 - 点击它就没有了,点击另一个,它将我带到前一个选定的第二个屏幕。
我以前从来没有遇到这种情况而且很困惑。
- (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];
}
谢谢, 尼克
答案 0 :(得分:9)
你回答了自己的问题。问题是您使用的是tableView:deselectRowAtIndexPath:
而不是tableView:didSelectRowAtIndexPath:
值得注意的是,这是因为deselect
在词典中did
之前出现的不幸事实,因此,xcode通常很棒的代码完成会让你感到高兴!
现在回去调试那些时间!