gpt4 book ai didi

ios - 推送 ViewController 给出 NSInvalidArgumentException

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:11:32 25 4
gpt4 key购买 nike

我是一名新手 iOS 开发人员,最近开发了几个 Android 应用程序,但我不熟悉 iOS 行话。让我解释一下我的问题。

我想使用两个不同的 UIViewController。我已经为两个 Controller 创建了 .h.m 文件。我的计划是在第一个 View Controller 出现在屏幕上五秒钟后将第二个 View Controller 推到第一个 View Controller 之上。我的意思是第一个 View Controller 类似于启动画面或类似的东西。

这是我的贡献。在第一个 View Controller 中,我定义了(其中一个当然实现了)这两个方法:

-(void) pushSecondController {
SecondViewController *secondController = [[SecondViewController alloc]
initWithNibName: nil
bundle: NULL];
[self.navigationController pushViewController: secondController animated: YES];
}

-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self performSelector: @selector(pushViewController:animated:)
withObject: nil
afterDelay: 5.0f];
}

第二个 View Controller 看起来像这样:

- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.title = @"Second Controller";
}

我只更改了 viewDidLoad 方法。当我运行模拟器时,第一个 View Controller 运行良好,等待 5 秒后崩溃。输出看起来像:

2012-08-24 10:46:34.104 NavApplication[20355:f803] -[ViewController pushViewController:]: unrecognized selector sent to instance 0x6e7f780
2012-08-24 10:46:34.107 NavApplication[20355:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController pushViewController:]: unrecognized selector sent to instance 0x6e7f780'

让我再问一个问题:我知道 methodNamemethodName: 之间存在差异。谁能解释一下有什么区别?

如有任何帮助,我们将不胜感激。

更新:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window makeKeyAndVisible];
[self.window addSubview: self.navigationController.view];
return YES;
}

最佳答案

@selector(pushViewController:animated:) 更改为 @selector(pushSecondController)

关于ios - 推送 ViewController 给出 NSInvalidArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12105497/

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