Calling a ModalView inside a ModalView From A SplitView Controller

Discussion in 'iOS Programming' started by rickjackson, Mar 24, 2011.

  1. rickjackson macrumors newbie

    Joined:
    Dec 24, 2010
    #1
    Hello,

    I have created a splitview based application and in the appDelegate applicationdidFinishLaunchingWithOptions method i am showing a popup

    Code:
    -(BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
        [self.window addSubview:splitViewController.view];
        [self.window makeKeyAndVisible];
    
        ModalScreenPopup *modalpopup = [[ModalScreenPopup alloc] init];
        [modalpopup setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
        [modalpopup setModalPresentationStyle:UIModalPresentationFullScreen];
    
        [splitViewController presentModalViewController:modalpopup animated:NO];
        [modalpopup release];
        
        return YES;
    }
    
    -(void) OpenTradeShowListingPopup
    {
    	[splitViewController dismissModalViewControllerAnimated:YES];
    	
    	TradeShowListing *modalTradeShowListing = [[TradeShowListing alloc] init];
    	
    	[modalTradeShowListing setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    	[modalTradeShowListing setModalPresentationStyle:UIModalPresentationFullScreen];
    	
    	[splitViewController presentModalViewController:modalTradeShowListing animated:YES];
    	
        [modalTradeShowListing release];
    }
    

    ModalScreenPopup has 2 buttons name Synchronize and continue with app and when i click on the synchronize button i am calling OpenTradeShowListingPopup method which is also declared in the appDelegate file. That method calls another popup but now the result i am getting is first modal is getting dismissed but second popup is not getting calleed


    what should i do any help will be appreciated.

    if any want to have a look at my issue here i have created a sample app with the same issue is replicated

    If some 1 want to see the issue i have created a sample application with the replicated the same issue here is the link : http://www.filefactory.com/file/ca4001f/n/2_Modal.zip
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    I saw u posted this also at iPhoneDevSDK, i think the major issue here is the thought of the app, when to call what screens.
    At the appdelegate u have a function, u are "calling" on your modalview, why isn't this function on that viewController then?
    I think the problem is, it's not calling ur second popup, because we can't see how u call the second popup neither, so if u do a shared delegate (which I don't think is what u want, for code cleaning issues etc).

    Do it like this.

    remove the function OpenTradeShowListingPopup in your appdelegate, and put it in your ModalScreenPopup viewController.
    So u can keep track of where what goes wrong.
     
  3. rickjackson thread starter macrumors newbie

    Joined:
    Dec 24, 2010
    #3
    Hey jnoxx thanks for reply. I will implement as what u have said and get back to you on this.
     
  4. rickjackson thread starter macrumors newbie

    Joined:
    Dec 24, 2010
    #4
    Hey jnoxx I tried it but its not working. Here is the Code i tried

    ===> APP DELEGATE

    Code:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
        
        // Override point for customization after app launch.
        
        // Add the split view controller's view to the window and display.
        [self.window addSubview:splitViewController.view];
        [self.window makeKeyAndVisible];
    	
    	
    	Modal1 *modalTradeShowListing = [[Modal1 alloc] init];
    	
    	[modalTradeShowListing setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    	[modalTradeShowListing setModalPresentationStyle:UIModalPresentationFullScreen];
    	
    	[splitViewController presentModalViewController:modalTradeShowListing animated:YES];
        
        return YES;
    }
    I have removed OpenTradeShowListingPopup method from my app delegate and added the same in my ModalScreen Popup

    ===> MODALSCREENPOPUP.M

    Code:
    - (void) OpenTradeShowListingPopup
    {
    	[self dismissModalViewControllerAnimated:YES];
    	
    	TradeShowListing *modalTradeShowListing = [[TradeShowListing alloc] init];
    	
    	[modalTradeShowListing setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    	[modalTradeShowListing setModalPresentationStyle:UIModalPresentationFullScreen];
    	
    	[self presentModalViewController:modalTradeShowListing animated:YES];
    	
        //[modalTradeShowListing release];
    }
    Now here i did a different thing instead of using splitviewcontroller i used self cause i am not getting any reference of splitview controlller.

    so now when i click on the syncronize button i have set the IBAction using interface builder to OpenTradeShowListingPopup method .

    But the result is same its not working.......
     
  5. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #5
    Hey, The problem is, that u are thinking of you're application wrong, u have to be carefull with the modalviewControllers.
    Just use 1, and put a navigation in there, and then push the next one like that?
    Because I can fix it for u, but this is really bad coding. (the one u supposed).

    good luck.

    PS: also be carefull with the doing self, just like that.
    U have to give it parameters.
    like in the appdelegate, do self.splitViewController.
    or self.view etc ;)
     
  6. rickjackson thread starter macrumors newbie

    Joined:
    Dec 24, 2010
    #6
    Hey Jnox Thanks For reply..... You said this is really bad coding. I will improve on it cause its just 2 months i have started with my iphone coding so can u just point me to some good tutorial for good coding practices.


    Thanks
     
  7. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #7
    I'm not being rude, and saying u are a bad coder.
    I just mean, the overal thinking of the application is wrong, I mean, how u gonna handle ur windows etc.
    I would suggest, u look up
    "iPhone navigationController tutorial"
    And implement that in your first ModalView ^_-
    Or just redo the whole idea, into a navigation :)
     
  8. dejo, Mar 24, 2011
    Last edited: Mar 24, 2011

    dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Is your class name Modal1 or MODALSCREENPOPUP?

    Why do you think it's bad coding? The View Controller Programming Guide for iOS even states:
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    Try removing the dismissal of the first modal view (highlighted in red) and let us know what happens.
     
  10. rickjackson thread starter macrumors newbie

    Joined:
    Dec 24, 2010
    #10
    hey Dejo thanks for ur reply.... Its not working :(. Can u just have a look at my sample application and track me where i am going wrong.

    Because of some restrictions i am not allowed to upload the real app but created a sample app which contains the same code but different view name : MODAL1 and MODAL2

    // APP DELEGATE

    Code:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
        
        // Override point for customization after app launch.
        
        // Add the split view controller's view to the window and display.
        [self.window addSubview:splitViewController.view];
        [self.window makeKeyAndVisible];
    	
    	
    	Modal1 *modalTradeShowListing = [[Modal1 alloc] init];
    	
    	[modalTradeShowListing setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    	[modalTradeShowListing setModalPresentationStyle:UIModalPresentationFullScreen];
    	
    	[splitViewController presentModalViewController:modalTradeShowListing animated:YES];
        
        return YES;
    }
    
    - (void) OpenTradeShowListingPopup
    {
    	//[splitViewController dismissModalViewControllerAnimated:YES];
    	
    	Modal2 *modalTradeShowListing = [[Modal2 alloc] init];
    	
    	[modalTradeShowListing setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    	[modalTradeShowListing setModalPresentationStyle:UIModalPresentationFullScreen];
    	
    	[self.splitViewController presentModalViewController:modalTradeShowListing animated:YES];
    	
        //[modalTradeShowListing release];
    }
    // MODAL 1 CONTAINS THE BUTTON AND ONTOUCHINSIDE TRIGGERING THIS EVENT

    Code:
    -(IBAction) ClickMe
    {
    	Modal2ViewAppDelegate *appDelegate1 = (Modal2ViewAppDelegate*)[[UIApplication sharedApplication]delegate];
    	
    	[appDelegate1 OpenTradeShowListingPopup];
    }
     
  11. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #11
    Hey Dejo,
    Well, i'm not saying, in this case specific it's bad coding, don't get me wrong.
    The problem is, modals are easy to show and hide. And most new programmers, start using them wrong, so I'm also not saying, the OP is doing it all wrong, just don't wonna set him on a bad way, because the HIG also says, that they reject apps for overusing Modal View Controllers :)
    So, I allways recommand using as much basic navigation as there is :)
    I was checking out his project, and it's doable ofcourse, without using the appdelegate.

    That's why i suggested the nav controller, inside the modal view, allways perfect solution for me :)
    But every programmer thinks different too, so good luck.
     
  12. rickjackson thread starter macrumors newbie

    Joined:
    Dec 24, 2010
    #12
    Hey JNOXX By Using UINAVIGATION Controller i am able to solve my problem.

    Here is the code

    Code:
    -(void) OpenTradeShowListingPopup
    {	
    	TradeShowListing *modalTradeShowListing = [[TradeShowListing alloc] init];
    	
    	UINavigationController *ncTradeShowController = [[UINavigationController alloc] initWithRootViewController:modalTradeShowListing];
    	ncTradeShowController.title = @"TradeShow Listing";
    	
    	[modalTradeShowListing setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    	[modalTradeShowListing setModalPresentationStyle:UIModalPresentationFullScreen];
    	
    	[self presentModalViewController:ncTradeShowController animated:NO];
    	
        [modalTradeShowListing release];
    	[ncTradeShowController release];
    }

    Thank you all.

    I will post again with more questions :p
     
  13. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #13
    Haha, well, that's not exactly what I meant.
    A navigationController is like the settings, if u press a button, it will load another view on the stack :)
    U are now, setting a modalview inside ur navigation?

    Should be more like this

    Code:
     -(void) OpenTradeShowListingPopup
    {	
    	TradeShowListing *modalTradeShowListing = [[TradeShowListing alloc] initWithNibName:@"TradeShowListing" bundle:nil];
    	
    	UINavigationController *ncTradeShowController = [[UINavigationController alloc] initWithRootViewController:modalTradeShowListing];
    	ncTradeShowController.title = @"TradeShow Listing";
    	
    [self.ncTradeShowController pushViewController:nextController];
    
    }
    Well, it's really confusing, u have to put some stuff outside, not all in 1 method :p so u can reference from other classes too :)
    like the UINavigationController, i mostly declare it in the H file, so i can acces it from other files too. via property.

    Something like that ;)

    U can allways post more questions :)
     
  14. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    First, when you say "it's not working", you should try to be more specific. What's not working? Are you getting warnings/errors? Is it crashing? Is code you're expecting to get called not being called? Etc.

    Alright, on to the real issue: The problem with your given code is that you were trying to present your second modal view as a child of the splitViewController when you already have a modal view presented (the first one). If you truly want to create a chain of modal views (something you need to really justify to yourself), then you need to present the second modal view as a child of the first modal view by placing your OpenTradeShowListingPopup inside your Modal1 code and then presenting Modal2 like so:

    ===> Modal1.m
    Code:
    - (void) OpenTradeShowListingPopup
    {
        Modal2 *modalTradeShowListing = [[Modal2 alloc] init];
    	
        [modalTradeShowListing setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
        [modalTradeShowListing setModalPresentationStyle:UIModalPresentationFullScreen];
    	
        [self presentModalViewController:modalTradeShowListing animated:YES];
    	
        [modalTradeShowListing release];
    }
    
    Also, you're calling this a popup. Do you truly want a modal view in this case or would a UIPopoverController usage actually suit it better? Think about that.

    Ah, thanks for the clarification, jnoxx. Yes, chaining modal views always need to be considered a last option, as it were, and only done if the circumstances truly justify it.
     

Share This Page