gpt4 book ai didi

ios - pushviewcontroller 不起作用?

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

viewcontroller 上有一个按钮,当我单击 按钮 pushviewcontroller 不起作用。


我的 appdelegate.m 文件:

- (BOOL)applicationUIApplication *)application **didFinishLaunchingWithOptionsNSDictionary** *)launchOptions 
{
self.window = [[UIWindow alloc] initWithFrame:EK_SCREEN_BOUNDS];

ExampleViewController *exampleViewController = [ExampleViewController new];

self.window.rootViewController = exampleViewController;

[self.window makeKeyAndVisible];

return YES;
}

按钮点击方法(在ExampleViewController中):

mainViewController *frm = [mainViewController new];
[self.navigationController pushViewController:frm animated:YES];

如何触发按钮点击事件?

最佳答案

使用以下代码更新您的 AppDelegate.m 文件

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
ExampleViewController *exampleViewController = [ExampleViewController new];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:exampleViewController];
self.window.rootViewController = navController;
//self.window.backgroundColor = [UIColor lightGrayColor];
[self.window makeKeyAndVisible];

The problem is that you are not initializing rootViewController from navigation controller. So, when you push a view controller on navigation controller it doesn't work. Because you never initialize a navigation controller.

关于ios - pushviewcontroller 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30995106/

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