gpt4 book ai didi

objective-c - UITableView 没有正确选择

转载 作者:太空狗 更新时间:2023-10-30 03:59:37 25 4
gpt4 key购买 nike

我正在开发一个 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];

}

谢谢,尼克

最佳答案

您回答了自己的问题。问题是您使用了 tableView:deselectRowAtIndexPath: 而不是 tableView:didSelectRowAtIndexPath:

值得注意的是,这是由于一个不幸的事实,即 deselect 在字典中出现在 did 之前,因此,xcode 通常很棒的代码补全功能会提示您!

现在回去调试那些时间吧!

关于objective-c - UITableView 没有正确选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9243623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com