简体   繁体   English

关闭以模态显示的视图使标签栏控制器(种类)重置

[英]Dismiss Modally presented view makes tab bar controller (kind of) reset

I have an app which has tab bar controller as main controller. 我有一个应用程序,其中有标签栏控制器作为主控制器。 Each tab has a series of views with navigation controller and I normal push and pop those view in stack. 每个选项卡都有一系列带有导航控制器的视图,我通常将这些视图推入并弹出到堆栈中。

Weird problem is 奇怪的问题是

Case 1 : If I create a UINavigationController and make a new viewController as its root, and present this NavigationController. 情况1:如果我创建一个UINavigationController并创建一个新的viewController作为其根,然后显示此NavigationController。 Within this new navigation stack, I can easily present a view modally and dismiss it without a problem. 在这个新的导航堆栈中,我可以轻松地模态呈现视图并将其毫无问题地关闭。

Case 2: Now without make a new UINavigationController, I present a view, and when I dismiss a view, the view beneath is behave weirdly. 情况2:现在,无需创建新的UINavigationController,我将呈现一个视图,而当我关闭视图时,下面的视图的行为将很奇怪。 For example, it's the presenting view was UICollectionView, it just scroll back to 1st cell, like it's doing "reload" action and "scrollTo" the first cell. 例如,它的呈现视图是UICollectionView,它只是滚动回到第一个单元格,就像在执行“重新加载”操作和“ scrollTo”第一个单元格一样。 If the presentingView is a pushed view from rootView, it will just popToRoot view, which is definitely not intended. 如果presentingView是从rootView推送的视图,则它将只是popToRoot视图,这绝对不是故意的。

I didn't have this problem until I implement UITabbarController, so I guess, I should know more that's going on under the hood when presenting a view and dismiss a view in UITabbarController. 在实现UITabbarController之前,我没有这个问题,所以我想,我应该知道在呈现视图并在UITabbarController中关闭视图时幕后的情况。

I GUESS, when dismiss a view in UITabbarController view, it sort of "RESET" everything to the very first view of it's current tab. 我猜,在UITabbarController视图中关闭视图时,它会将所有内容“重置”到当前选项卡的第一个视图。 I really am not sure it's trure though. 我真的不确定那是真的。

I know it's kind of conceptual, but I can't help to think there must be something critical I am missing here. 我知道这是一种概念上的想法,但是我不禁想到这里肯定缺少一些关键的东西。

I made silly mistake that I sublclass UITabbarController and define navigation controlllers in viewDidAppear instead viewdidLoad, so when I make the window's rootview to tabbar controller, the navigation controllers are not set properly. 我犯了一个愚蠢的错误,即我将UITabbarController子类化,并在viewDidAppear中而不是viewdidLoad中定义导航控制器,因此,当我将窗口的rootview设置为tabbar控制器时,导航控制器的设置不正确。 That's why all punky things happened. 这就是为什么所有棘手的事情都发生了的原因。 It would be nicer if just crash instead of this weird behaviors. 如果只是崩溃而不是这种奇怪的行为,那就更好了。

You can try this to go back to your first viewcontroller. 您可以尝试此操作以返回到第一个ViewController。

 - (IBAction)buttonPressedFromVC2:(UIButton *)sender { [self dismissViewControllerAnimated:YES completion:nil]; } // This is going back to VC1. 

This method is will be in second viewcontroller.m file. 此方法将在第二个viewcontroller.m文件中。 It is button click method. 是按钮点击方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM