Modal view controller presenter problem

Discussion in 'iOS Programming' started by moonman239, Mar 6, 2014.

  1. moonman239, Mar 6, 2014
    Last edited: Mar 6, 2014

    moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    I have a modal view controller, whom I'll call Bob. Bob is presented by Amy, who is Bob's delegate. When the user is done using Bob, Bob calls a method that is defined in Bob's delegate protocol. Amy responds by dismissing Bob.

    There is a piece of code that is supposed to be run after Amy's parent view loads. It runs well when Amy is loaded into the navigation controller's stack, but not when Bob calls the aforementioned delegate method. If the code is in viewDidAppear, Bob won't even go away.

    I did not knowingly cause this behavior, and I am not using any relevant third-party code.
     
  2. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
  3. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #3
    When another view controller causes Amy to be displayed, the code in Amy's viewDidLoad method is executed. That does not happen when Bob is dismissed.
    I moved the code to Amy's viewDidAppear method. After that, I ran the app. Bob didn't even disappear.

    Here's the code that defines how Amy responds:

    Code:
    -(void)bobDelegateMethod
    {
    // Irrelevant code
        [self dismissViewControllerAnimated:false completion:nil];
    }
    
     
  4. moonman239, Mar 6, 2014
    Last edited: Mar 6, 2014

    moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #4
    OK, it looks like the view did appear for a very short amount of time before Bob reappears. However, this is not the behavior I expect. I think I can fix my app.

    ----------

    Problem solved (sort of).

    Edit: For some reason, the delegate method gets called multiple times. I don't know why.
    Edit #2: it must be because Bob registered Amy to listen for an AVPlayerItem notification. I changed that.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Describing code is not a great way to get help with debugging. Please provide actual code. Because what you describe in English as the flow may not be what the code is actually doing. There may be some "loss in translation". If you're wary to provide code from your real project (due to privacy concerns, perhaps), build a test project that reproduces the issue. Provide that code.
     

Share This Page