iOS: popViewController unexpected behavior

后端 未结 7 1935
迷失自我
迷失自我 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: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!

提交回复
热议问题