gpt4 book ai didi

ios - 从另一个 UIViewController 推送一个 UIViewController - 如何?

转载 作者:行者123 更新时间:2023-11-29 13:23:12 24 4
gpt4 key购买 nike

我有一个 UIViewController 子类(比如 BBB),它继承自已经编写的自定义 UIViewController 类(比如 AAA)。 BBB 类中有一个 UITableView,当用户点击 UITableView 的任何单元格时,我想推送另一个 UIViewController 类(比如 CCC)。

因此,我尝试在 BBB 的 tableView: didSelectRowAtIndexPath: 方法中推送 CCC Controller 。

我的代码是,

CCC *ccc = [[CCC alloc] init];
[self.navigationController pushViewController:ccc animated:YES];
[ccc release];

点击单元格时没有任何反应,所以我通过以下代码检查了 BBB 类的导航 Controller 。

if (self.navigationController == nil)
{
NSLog(@"Navigation controller is nil");
}

消息已成功打印 :) 所以,我尝试将一些东西分配给导航 Controller ,但不幸的是,它是一个只读属性。

然后我尝试通过将 ccc 指定为 rootviewcontroller 来创建本地 UINavigationController,然后尝试推送该本地导航 Controller 。它抛出异常“不支持多次推送同一个 View Controller 实例”。

我的问题是,

  • 是否可以找到导航 Controller 在 AAA 类中获取 nil 值的位置?我没有在我的 BBB 类中将导航 Controller 设置为 nil,并且我在类 AAA 中发现是否有任何类似“self.navigationController = nil”的语句。但没有什么是那样的。

  • CCC课怎么推送?

谢谢

最佳答案

将其放入您的应用委托(delegate)中,您的代码的第一个版本应该可以工作。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
AAA *aaa = [[AAA alloc] init];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController: aaa];
[self.window makeKeyAndVisible];

return YES;
}

关于ios - 从另一个 UIViewController 推送一个 UIViewController - 如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13846547/

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