iOS: popViewController unexpected behavior

后端 未结 7 1888
迷失自我
迷失自我 2020-12-02 16:52

I\'ve been searching the internet for a solution. There\'s nothing I could find. So: I\'m using a UINavigationController. I am pushing two UIViewControllers onto it. In the

相关标签:
7条回答
  • 2020-12-02 17:16

    I have created a drop-in replacement for UINavigationController that will queue animations for you and avoid this problem entirely.

    Grab it from BufferedNavigationController

    0 讨论(0)
  • 2020-12-02 17:21

    yeah, unfortunately apple did not synchronize UINavigationController's animations. Andrew's solution is excellent, but if you don't want to cover its whole functionality, there is a simpler solution, override these two methods :

    // navigation end event
    
    - ( void )  navigationController    : ( UINavigationController* ) pNavigationController 
                didShowViewController   : ( UIViewController*       ) pController 
                animated                : ( BOOL                    ) pAnimated
    {
    
        if ( [ waitingList count ] > 0 ) [ waitingList removeObjectAtIndex : 0 ];
        if ( [ waitingList count ] > 0 ) [ super pushViewController : [ waitingList objectAtIndex : 0 ] animated : YES ];
    
    }
    
    
    - ( void )  pushViewController  : ( UIViewController* ) pController 
                animated            : ( BOOL ) pAnimated
    {
    
        [ waitingList addObject : pController ];
        if ( [ waitingList count ] == 1 ) [ super pushViewController : [ waitingList objectAtIndex : 0 ] animated : YES ];
    
    }
    

    and create an NSMutableArray instance variable called waitingList, and you are done.

    0 讨论(0)
  • 2020-12-02 17:22

    I came across a similar situation in my code and the message said:

    nested push animation can result in corrupted navigation bar

    Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree >might get corrupted.

    My finding to this issue was that I was pushing 2 view controllers one after the other in quick succession and both were animated.

    In your case it seems that you might be popping multiple view controllers with animation one after the other.

    Hence, while one view is undergoing animation you should not start animation on another view.

    I also found that if I disabled animation on one view, the error message disappeared.

    In my case it was a problem with the flow logic as I did not intend to push 2 view controllers one after the other. One was being pushed within the switch case logic and another after its end.

    Hope this helps someone.

    0 讨论(0)
  • 2020-12-02 17:23

    I had this problem, too, and here's what was causing mine:

    1. In RootViewController, I am using several UISegmentedControl objects to determine which of many views to load next.
    2. In that (sub/2nd) view, I was popping (by using the "Back" button) back to RootViewController.
    3. In RootViewController, I was handling viewWillAppear to "reset" each of my UISegmentedControl objects to a selectedSegmentIndex of -1 (meaning no segment looks "pressed").
    4. That "reset" triggered each of my UISegmentedControl objects to fire their associated (and separate) IBActions.
    5. Since I wasn't handling for a "selection" of -1, I had multiple methods firing at the same time, all trying to push a different view.

    My fix? I tightened up my if...then statements and bailed on executing any code in my UISegmentedControl IBActions when selectedSegmentIndex == -1.

    I'm still not sure why I got "pop" animation errors and not "push" errors, but at least figured out my error and got it fixed!

    Hope this helps someone else!

    0 讨论(0)
  • 2020-12-02 17:24

    This problem happen with me when i use storyboards. I've made a mistake: I have a UIButton with an action to performSegueWithIdentifier. So i link the push segue with Button with the other ViewController so occur this problem.

    To solve: Link the button action in UIButton and link the push segue between two ViewControllers.

    0 讨论(0)
  • 2020-12-02 17:27

    You can get this anytime that you try to pop before viewDidAppear. If you set a flag, then just check that flag in viewDidAppear, you wont have a problem.

    0 讨论(0)
提交回复
热议问题