iOS的执行了VC执行了popToRootViewControllerAnimated之后再直接执行VC.tabBarController.selectedIndex不管用解读

【导航控制器总结-导航控制器栈 Objective-C语言】 阅读详情
前言

今天我在使用VC.tabBarController.selectedIndex的时候出现了这个问题,我首先用导航控制器跳转了很多个界面,然后想直接回到根控制器tabBarController的其他的控制器上,也就是执行VC.tabBarController.selectedIndex = 1这样的操作,可以直接操作的呀,当然肯定行了,会有个问题就是你再点击之前的那个标签控制器的话,还是显示之前那个界面并没有回到首页。所以我的打算就是先回到导航控制器的根控制器的,然后再切换根控制器。

遇到的问题
[viewVC.navigationController popToRootViewControllerAnimated:NO];
viewVC.tabBarController.selectedIndex = 1;

我这样写的看上去很正常的,但是结果就是只执行了pop的方法,但是下面虽然也执行了,但是并没有作用,标签控制器并没有切换,只是回到根控制器了。后来尝试让他们切换一下前后位置,很奇怪的事居然可以行的通了,都执行了,切回来的时候而且之前也回到首页了。

分析原因

其实,我之后分析一下,就可以很明白的看出来什么原因,我们可以看到执行[viewVC.navigationController popToRootViewControllerAnimated:NO];之后,这个操作是把栈上面的数据都清空,只保留栈底的数据,所以viewVC被推出栈的时候,也就释放了ViewVC变为nil,这个时候执行了,viewVC.tabBarController.selectedIndex肯定不起作用了呀,viewVC = nil。我们再来看一下先执行viewVC.tabBarController.selectedIndex
再执行popToRootViewControllerAnimated方法时候,我们知道tabBarController标签控制器的的子控制器navigationController是不会被释放的,除非程序kill或者crash才会被释放,所以我们先执行viewVC.tabBarController.selectedIndex时,在执行了之后ViewVC还是在navigationController的栈中,没有被释放,所以再执行popToRootViewControllerAnimated也是行的通的。

解决办法
    viewVC.tabBarController.selectedIndex = 1;
    viewVC.tabBarController.tabBar.hidden = NO;
    if (![viewVC isEqual:focusNav.viewControllers.firstObject]) {
        [viewVC.navigationController popToRootViewControllerAnimated:NO];
    }

之所以viewVC.tabBarController.tabBar.hidden = NO;这句代码,防止tabbar隐藏了,保证不隐藏。这样就可以解决问题。

Objective-C动画学习之视图跳转方式 视图跳转方式:(push pop)[self.navigationController pushViewController:(nonnull UIViewController *)animated:(BOOL)]; popToRootViewControllerAnimated:(BOOL) popToViewController:(nonnull UIViewController *)#anim 阅读详情

相关推荐

Gromacs实战:从蛋白质-小分子对接到分子动力学模拟全流程解析

本文详细解析了使用Gromacs进行蛋白质-小分子对接和分子动力学模拟的全流程,包括文件准备、拓扑生成、复合物构建、溶剂化处理、能量最小化及平衡模拟等关键步骤。通过实战案例,帮助研究者验证药物分子与靶标蛋白的结合稳定性,提升分子动力学模拟的效率和准确性。

weixin_29216353的博客 380

popToRootViewControllerAnimated:(BOOL)animated

for(UIViewController *controller in self.navigationController.viewControllers){ if([controller isKindOfClass:[HIHomepageController class]]){ HIHomepageController*owr = (HIHomepageC

BlingbringBling的博客 727

从Google到LLVM:5种主流clang-format预设风格横向对比(含代码对比图)

本文横向对比了LLVM、Google、Chromium、Mozilla和WebKit五种主流的clang-format预设代码风格。通过同一段C++代码的格式化效果对比图,直观展示了它们在指针对齐、大括号换行、缩进等关键细节上的差异,并提供了基于团队背景与项目基因的选型决策指南。

weixin_28828243的博客 442

UI之UINavigationController

UINavigationController是UI中很常用的管理多个控制器之间跳转的控制器,叫导航控制器

IT李菜鸟的博客 857

MOOS-ivp 实验三 MOOS简介(3)

MOOS-ivp 实验三 MOOS简介(3) 继上一篇文章继续对实验进行记录 提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录MOOS-ivp 实验三 MOOS简介(3)六、A Simple Example with pXRelay1.pXRelay基本使用2.pXRelay简单例子3.pXRelay实验七、First Experiments in Modifying MOOS App Code1.下载一个MOOS模板文件2.打开MOOS模板文件总结 六、A Simple E

weixin_44151170的博客 2534

从服装打版到激光切割:二维异形件排版算法在实际生产中的避坑指南

本文深入探讨二维异形件排版算法在服装、家具等行业的实际应用,对比NFP和重叠移除两种核心策略的优缺点,并提供算法落地的五大实战陷阱与解决方案。通过案例分析和技术要点解析,帮助生产管理者提升材料利用率5%-15%,优化生产效率。

weixin_28717431的博客 416

iOS开发 -- iOS 14下popToRootViewControllerAnimated:YES 导致TabBar隐藏的问题

我们处理UITabbar在push的时候的显示和隐藏, 之前因该是如下的操作: - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { if (self.viewControllers.count > 0) { viewController.hidesBottomBarWhenPushed = YES; } else { viewCon

张福润的博客 5744

RPMsg:协议简介

两台计算机可以通过TCP/IP进行通信,那么同一颗芯片上的两个核心怎么通信呢?

SunnyZhou-1024的博客 1万+

tabbarcontroller 内嵌导航 控制器,2层push hide tabbar 后 ,第二层直接返回根视图控制器选择tabbarcontroller的其它vc 无法显示 tabbar的 问题...

场景如标题 这样不行: [self.navigationController popToRootViewControllerAnimated:YES]; MainViewController *mainCtrl = [(AppDelegate *)[UIApplication sharedApplication].delegate mainCtrl]; mainCtrl.sele...

178

SAP_通用模块-MASS批量操作技巧

SAP_MM模块-MASS/MM17批量更新主数据详细教程

风沙的博客 2164

python代码实现了一个基于图注意力网络(GAT)和长短期记忆网络(LSTM)的股票成交量预测模型

自定义数据集类:定义了类,继承自。该类用于生成股票数据的时间序列样本,每个样本包含一个长度为seq_length的时间序列和对应的目标成交量。数据加载器:使用DataLoader对数据集进行批量加载,设置批量大小为 64,并开启数据打乱功能。GAT - LSTM 模型:定义了GAT_LSTM类,继承自。该模型结合了 GAT 和 LSTM 两种神经网络:GAT 部分:使用GATConv处理全局图特征,捕获股票之间的相互关系。LSTM 部分:使用nn.LSTM处理时间序列数据,捕捉时间序列的动态变化。

huanghm88的专栏 424

iOS自定义TabBar使用popToRootViewControllerAnimated返回后tabbar重叠

解决方法 所以方法就是:遵循UINavigationController的代理,用代理方法解决该Bug,代码如下: 实现代理方法: -(void)navigationController:(UINavigationController*)navigationControllerwillShowViewController:(UIViewController*)viewControll...

weixin_37543822的博客 132

SAP Fiori Launchpad 上看不到任何 tile 应该怎么办?

中心UI组件是一个框架,为所有SAPFiori应用程序提供公共基础设施SAPFiorilaunchpad是所有SAPFioriUI的基础,并为SAPFiori应用程序提供基本功能,如登录,界面大小,应用程序之间的导航,和基于角色的应用程序目录。ABAP前端服务器包含所有基础设施组件,用于为客户端生成SAPFiori应用程序特定的UI,并与SAPBusinessSuite后端系统通信。SAPFiori应用程序的处理过程如下首先,客户端加载SAPFiori应用程序的界面。...

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 940

iOS 14下popToRootViewControllerAnimated:YES 导致TabBar隐藏的问题

每次大版本更新都会出现一些莫名的问题,这一次苹果升级到iOS14也没有逃脱…… 问题 在处理UITabbar在push的时候的显示和隐藏, 通常是像下面这样处理: - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { if (self.viewControllers.count > 0) { viewController.hidesBottomBarWhen

倚栏静望的博客 4006

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

“ios14 popToRootViewControllerAnimated 底部tabbar消失”问题处理

ios14 popToRootViewControllerAnimated 底部tabbar消失问题处理 解决方法是: 在UINavigationController 类重写以下方法: -(NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated { if (animated) { UIViewController *

weixin_42050662的博客 1858

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

iOS自定义TabBar使用popToRootViewControllerAnimated重叠问题解决

先看下现象吧,如下图: 不仅仅重叠了,而且还把图标给覆盖了。很郁闷。 折腾了很久,终于找到解决办法了。 在自定也的NavigationController中添加如下代码: - (void)viewDidLoad{ [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self s

首字母大写-博客 4536

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

iOS狂暴之路---视图控制器(UIViewController)使用详解

一、前言 在之前的一片文章中已经介绍了从iOS的第一个应用中能学习到哪些知识点在那篇文章中主要介绍了一个iOS程序的启动过程和应用的几大对象,以及应用的生命周期,同时也介绍了应用中的控制器知识点,介绍了其生命周期方法,那么对于一个iOS应用一般都是会包含多个页面,而每个页面就是一个控制器...

chupu2979的博客 186

iOS开发中ViewController使用详解

一、前言 在之前的一片文章中已经介绍了 从iOS的第一个应用中能学习到哪些知识点 在那篇文章中主要介绍了一个iOS程序的启动过程和应用的几大对象,以及应用的生命周期,同时也介绍了应用中的控制器知识点,介绍了其生命周期方法,那么对于一个iOS应用一般都是会包含多个页面,而每个页面就是一个控制器,一个控制器一般都是关系到一个UIView的,但是我们在真正使用这些控制器的时候会发现,多个页面之间的

susu79的专栏 1万+

iOS自定义tabbar后popToRootViewContriller和poptoviewcontroller时出现两个tabbar 的解决办法

iOS自定义tabbar后popToRootViewContriller和poptoviewcontroller时出现两个tabbar 的解决办法 问题:iOS自定义tabbar后popToRootViewContriller和poptoviewcontroller时出现两个tabbar 1.自定义代码: - (void)viewWillAppear:(BOOL)anima

Ios_zerozheng的专栏 2800

UITabBarController的selectedIndex属性不起作用?

今天想做一个查找的程序,找到后页面跳到内容处,发现设置了UITabBarController的selectedIndex属性不起作用。找到了原因,记录下来:UITabBarController默认显示Index=0的页面,如果要想在程序启动时就指定显示的页面,tabBar.selectedIndex一定要写在tabBar.viewControllers之后,也就是说把页面序列加进TabBarCon...

weixin_42012181的博客 6926

popToViewController的用法已经关闭所ViewController的方法

popToViewController的用法  for (UIViewController *temp in self.navigationController.viewControllers) {            if ([temp isKindOfClass:[你要跳转到的Controller class]]) {               [self.navig

倾城一屁,博妹一笑。 7743

iOS真枪实弹的一些坑

iOS实战,使用第三方库,ui,审核的一些问题

C_orz 2609

[iOS][兼容性]iOS7 pushViewController,popViewControllerAnimated存在的问题

问题引入 最近在项目中,遇到一个问题:  实现类似于设置功能的简单应用,方法是中在storyboard中,基于UITableView 建立一个静态tableViewCell。基于这个静态cell直接在storyboard上拖拽到下一级Controller, 方法为push。 问题现象:ios8以上系统没有问题。到ios7系统,出现crash. 最后用下边博文的方法解

ruglcc's blog 2873

在popViewControllerAnimated后调用函数

<br />a(tableview)pushviewcontrol到b,b执行完动作后[[self navigationController] popViewControllerAnimated:YES];<br /> 返回a,有时需要a表格数据进行刷新,或调用其他方法,可以在a中的viewWillAppear函数中进行reloaddata或进行相关函数调用。

ios专栏 8910

iOS UITabBarController用法原理详解(一)、自定义tabbar

UITabBarController的原理: UITabBarController会一次性初始化所有子控制器,但是默认只加载第一个控制器视图,其他视图控制器只初始化默认不会加载,只有当需要显示的时候才loadView加载,为了能够将其他子控制器也正常显示在Tab bar中,我们访问了每个子视图控制器的视图以便调用其视图加载方法(viewDidLoad);当然,既然会调用子视图的初始化方法,...

代码解释生活 1万+

记录一个iOS tabar 消失的问题

在app中任意一个页面,点击某个功能按钮的时候, app都要选中第三个tab。

liubo的博客 1434
上一篇: iOS的关于类方法中创建的UIButton的添加的点击事件,点击button时crash的有趣的事
下一篇: app支持自动屏幕旋转的时候,横屏时,启动app的时候界面横屏的bug解决
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值