ios - AppDelegate 中的 PushingViewController 无法识别的选择器实例

标签 ios objective-c uiviewcontroller uinavigationcontroller

我一直在 stackoverflow 周围搜索,但无法解决我的问题,我的 AppDelegate.m 中有以下代码:

UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:storyboard bundle: nil];
        InternetConnectionViewController *controller = (InternetConnectionViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: noInternet];
        [navigationController pushViewController:controller animated:YES];

但是给了我一个错误...:

Uncaught exception: -[CustomSplitViewController pushViewController:animated:]: unrecognized selector sent to instance 0x17884860
2016-06-16 02:34:14.896 --[3340:1197655] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CustomSplitViewController pushViewController:animated:]: unrecognized selector sent to instance 0x17884860'
*** First throw call stack:
(0x20c6b91b 0x20406e17 0x20c712b5 0x20c6eee1 0x20b9a238 0x23005d 0xb1cb7f 0xb1cb6b 0xb21655 0x20c2db6d 0x20c2c067 0x20b7b229 0x20b7b015 0x2216bac9 0x2524d189 0x18abdb 0x20823873)
libc++abi.dylib: terminating with uncaught exception of type NSException
warning: could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available.

编辑 - 更新 我设法实现了它,现在正在工作......但是当我尝试这样做时:

UINavigationController *navigationController = self.navigationController;
 UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
    HomeViewController *controller = (HomeViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: viewC];
    [navigationController pushViewController:controller animated:YES];

在 InternetViewController 中它给了我以下错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setPanGestureEnabled:]: unrecognized selector sent to instance 0x16942a00'

最佳答案

在 AppDelegate.h 文件中创建属性

@property (strong, nonatomic) UINavigationController *navController;

然后

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

MainTabBarController *mainTabbarController = [storyboard instantiateViewControllerWithIdentifier:@"MainTabbar"];
self.navController = [[UINavigationController alloc] initWithRootViewController:mainTabbarController];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];

关于ios - AppDelegate 中的 PushingViewController 无法识别的选择器实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37855317/

相关文章:

ios - 是否可以将 ViewController 分配给 SwiftUI View ?

ios - cocoa : Can't remove child view controller

ios - 如何在按钮操作上从 UIView 移动到 UIViewcontroller

ios - 展开标签并转换为 Int()

ios - 将NSInteger和NSString转换为字节数组

objective-c - objective c singleton dispatch_once 实现更好?

iphone - 如何从点数组中绘制填充形状并在该形状内获得点击?

ios - 标签框未正确停留在 `UICollectionViewCell`

ios - 获取 ios 中每次更改的电池状态

ios - 即使在运行时设置 UIImage,如何在 UIImageView 上做弯角?