gpt4 book ai didi

iphone - PushViewController 不会对 UITableView 中的 didSelectRowAtIndexPath 执行任何操作

转载 作者:行者123 更新时间:2023-12-03 19:10:06 26 4
gpt4 key购买 nike

我有一个 UITableView,并且设置了 didSelectRowAtIndexPath,每次用户单击一行时都会调用它(我已使用 NSLog 验证它)。

但是,我想重新加载相同的 View 并更改不同的数据。例如,我正在显示远程 Web 服务器上的目录内容,一旦用户单击该行,我想重新加载 View 并显示所选目录(行)的内容。

我正在使用此代码:

FirstViewController *fvController = [[FirstViewController alloc] initWithNibName:@"MainWindow" bundle:[NSBundle mainBundle]];
fvController.currentDirectory = currentDirectory;
[self.navigationController pushViewController:fvController animated:YES];
[fvController release];
fvController = nil;

但是,它不执行任何操作并且程序继续运行。我假设我在 IB 中缺少连接?

最佳答案

没有任何反应的原因可能是 self.navigationControllernil,可能是因为您从未设置过。你的直觉是好的:当“什么也没发生”时,它几乎总是意味着某些东西是nil,而某些东西是nil的第一个原因是你没有连接它在IB中。

您的递归设计表明您对 View Controller 的工作原理有很好的理解。看起来你走在正确的道路上。一些主动提供的建议可以让您走得更远。而不是这段代码:

FirstViewController *fvController = [[FirstViewController alloc] initWithNibName:@"MainWindow" bundle:[NSBundle mainBundle]];
fvController.currentDirectory = currentDirectory;

我推荐一些看起来像这样的东西:

FirstViewController *fvController = [[FirstViewController alloc] initWithDirectoryPath:currentDirectory];

当然,您需要编写-initWithDirectoryPath:来调用-initWithNibName:bundle:。这会将 NIB 的名称推送到管理它的 View Controller 内,允许您将 -currentDirectory 设为只读或私有(private),因此没有人会在 View Controller 背后弄乱它,并且通常会使代码更容易理解和维护。

关于iphone - PushViewController 不会对 UITableView 中的 didSelectRowAtIndexPath 执行任何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1430850/

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