self.navigationController pushViewController执行不成功

本文详细介绍了在Objective-C开发环境中遇到self.navigationController无法正常推动视图控制器时的排查和解决方法,包括设置断点检查navigationController对象的有效性,确保其正确配置,以解决应用中导航流程的常见问题。
部署运行你感兴趣的模型镜像

 

 

self.navigationController pushViewController执行不成功

 

遇到这种情况,一般是self.navigationController不是有效的navigationController对象,可以设置断点查看该对象的值。

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

#import "TPNavigationController.h" #import "TPContainerViewController.h" #import "TPContainerNavigationController.h" #import "UIViewController+TPNavigationExtension.h" #import <TPFoundation/TPUIUtils.h> @implementation TPContainerNavigationController + (instancetype)wrapNavigationControllerWithViewController:(UIViewController *)viewController { return [[self alloc] initWithViewController:viewController]; } - (instancetype)initWithViewController:(UIViewController *)viewController { if (self = [super init]) { self.viewControllers = @[viewController]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // 禁用包装的vc的返回手势 self.interactivePopGestureRecognizer.enabled = NO; } - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { TPContainerViewController *fromContainer = (TPContainerViewController *)self.navigationController.topViewController; if (![self shouldKeepOrientationFromController:[fromContainer rootViewController] toController:viewController]) { [self ensureOrientationIsPortrait]; } // push一个包装后的控制器 TPContainerViewController *wrapViewController = [TPContainerViewController wrapViewController:viewController]; if (self.tpNavigationController.viewControllers.count >= 1) { if (@available(iOS 9.0, *)) { wrapViewController.hidesBottomBarWhenPushed = YES; viewController.hidesBottomBarWhenPushed = YES; } else { // for iOS 8, set tabbar hidden [[self tabBarController].tabBar setHidden:YES]; } } //使用Xcode12.0.1编译的App,在iOS14上运行时,当调用popToRootViewControllerAnimated:YES到vc栈中非相邻的vc时,会发现rootViewController的tabbar消失了,如果是popToRootViewControllerAnimated:NO则没问题 // 应该是官方的bug,先复写该方法解决 else { if (@available(iOS 14.0, *)) { viewController.hidesBottomBarWhenPushed = NO; } } [self.navigationController pushViewController:wrapViewController animated:animated]; } - (UIViewController *)popViewControllerAnimated:(BOOL)animated { NSInteger controllersCount = self.navigationController.viewControllers.count; if (controllersCount > 1) { TPContainerViewController *fromContainer = (TPContainerViewController *)self.navigationController.topViewController; TPContainerViewController *toContainer = self.navigationController.viewControllers[controllersCount - 2]; if (![self shouldKeepOrientationFromController:[fromContainer rootViewController] toController:[toContainer rootViewController]]) { [self ensureOrientationIsPortrait]; } } if (self.navigationController) { return [self.navigationController popViewControllerAnimated:animated]; } return [super popViewControllerAnimated:animated]; } - (NSArray<UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated { [self ensureOrientationIsPortrait]; return [self.navigationController popToRootViewControllerAnimated:animated]; } - (NSArray<UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated { [self ensureOrientationIsPortrait]; TPNavigationController *tpNavigationController = viewController.tpNavigationController; // pop到指定vc时应找到对应的tpContainerViewController NSInteger index = [tpNavigationController.tpChildViewControllers indexOfObject:viewController]; return [self.navigationController popToViewController:tpNavigationController.viewControllers[index] animated:animated]; } - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion { [self ensureOrientationIsPortrait]; [self.navigationController presentViewController:viewControllerToPresent animated:flag completion:completion]; } - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion { [self ensureOrientationIsPortrait]; [self.navigationController dismissViewControllerAnimated:flag completion:completion]; } - (void)setDelegate:(id<UINavigationControllerDelegate>)delegate { self.navigationController.delegate = delegate; } - (void)ensureOrientationIsPortrait { if (UIInterfaceOrientationIsPortrait([TPUIUtils getScreenOrientation])) { return; } if (@available(iOS 16.0, *)) { [self setNeedsUpdateOfSupportedInterfaceOrientations]; } [TPUIUtils changeScreenOrientationTo:UIInterfaceOrientationPortrait]; } - (BOOL)shouldKeepOrientationFromController:(UIViewController *)fromController toController:(UIViewController *)toController { SEL selector = @selector(controllersNeedToKeepOrientationWhenNavigating); if ([fromController respondsToSelector:selector]) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" NSArray *controllers = [fromController performSelector:selector]; #pragma clang diagnostic pop NSString *toControllerName = NSStringFromClass([toController class]); if ([controllers containsObject:toControllerName]) { return YES; } } return NO; } @end
09-27
func handleAddButtonClick(itemId: String){ switch itemId { case "autoAdd": if appContext.isVmsLogin && !showLocalDeviceOnly { let vc = DeviceAddSelectSiteViewController() vc.enterType = .batchAdd self.navigationController?.pushViewController(vc, animated: true) } else { let vc = DeviceBatchAddAutoSearchMainViewController() vc.addDeviceType = .all DeviceAdd.shared.reload(source: .fromAddButton) DeviceAdd.shared.model.addMethod = .byDiscover DeviceAdd.shared.model.listType = showLocalDeviceOnly ? .local : .remote DeviceAddContext.shared.clear() DeviceAddContext.shared.addDeviceType = .all DeviceAddContext.shared.addListType = showLocalDeviceOnly ? .local : .remote DeviceAddContext.shared.isBatchAdd = true self.navigationController?.pushViewController(vc, animated: true) } case "scan": DeviceAdd.shared.reload(source: .fromDeviceList) DeviceAdd.shared.model.addMethod = .byQRCode DeviceAdd.shared.model.listType = showLocalDeviceOnly ? .local : .remote DeviceAddContext.shared.clear() DeviceAddContext.shared.isCloudVmsAdd = appContext.isVmsLogin && !showLocalDeviceOnly DeviceAddContext.shared.addListType = showLocalDeviceOnly ? .local : .remote DeviceAddContext.shared.isBatchAdd = false guard let vc = UIStoryboard(name: "DeviceAddByQrCode", bundle: nil).instantiateViewController(withIdentifier: "DeivceAddByQrCodeMainViewController") as? DeivceAddByQrCodeMainViewController else { return } self.navigationController?.pushViewController(vc, animated: true) case "manuallyAdd": DeviceAdd.shared.reload(source: .fromAddButton) DeviceAdd.shared.model.addMethod = .byDiscover DeviceAdd.shared.model.listType = showLocalDeviceOnly ? .local : .remote DeviceAddContext.shared.clear() DeviceAddContext.shared.isCloudVmsAdd = appContext.isVmsLogin && !showLocalDeviceOnly DeviceAddContext.shared.addDeviceType = .all DeviceAddContext.shared.addListType = showLocalDeviceOnly ? .local : .remote DeviceAddContext.shared.isBatchAdd = true let vc = DeviceAddManuallyAddChooseDeviceAddTypeViewController() vc.fromAutoSearch = true self.navigationController?.pushViewController(vc, animated: true) case "addSite": if let vc = self.pageController.viewControllers?.first as? OnlineDeviceListViewController { vc.addSiteButtonClicked(UIButton()) } default: break } }
最新发布
11-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值