Resolved open a modalViewController at application launch

Discussion in 'iOS Programming' started by roberto.vigo, Feb 17, 2011.

  1. roberto.vigo, Feb 17, 2011
    Last edited: Feb 21, 2011

    macrumors newbie

    Joined:
    Feb 17, 2011
    #1
    Hi all,

    here is my problem: I have an iPad application based on a SplitViewController. When I launch the application, since it always starts in portrait mode, only the Detail pane is shown. All right. I want now to open a modalViewController at the application launch for login purpose, but I am not able to find out the right way. I grasp on the web the following code:

    Code:
    SampleModalViewController *sampleView = [[[SampleModalViewController alloc] init] autorelease];
    [sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
    [self presentModalViewController:sampleView animated:YES];
    
    and it runs nicely, but where do I have to place it in order to have the modal controller displayed at startup? I tried to override viewDidLoad in the DetailViewController, but it does not work.

    Thanks for your help! Roberto
     
  2. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    Hey,

    I had same trouble, and didn't like nobody helped me. So I will post my solution :) So u can keep happy coding ^_-

    In ur appDelegate
    Code:
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    -->

    Code:
    	LoginScreenController *modalLoginView = [[[LoginScreenController alloc] initWithNibName:@"LoginScreenController" bundle:nil] autorelease];
    	[modalLoginView setModalPresentationStyle:UIModalPresentationFullScreen];
    	[self.splitViewController presentModalViewController:modalLoginView animated:NO];
    
    BEFORE the
    Code:
    [window makeKeyAndVisible];
    Don't forget to import the "LoginScreenController.h" at top :)

    Good luck
     
  3. thread starter macrumors newbie

    Joined:
    Feb 17, 2011
    #3
    Thanks a lot, it works!

    By the way, I think that the crucial point I was missing was the .splitViewController in

    Code:
    [self.splitViewController presentModalViewController:modalLoginView animated:NO];
    
    Thanks again!
     
  4. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    No problem, that's what i'm here for ;)
     
  5. thread starter macrumors newbie

    Joined:
    Feb 17, 2011
    #5
    How to add the "resolved" prefix to the thread?

    thanks
    Roberto
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Make sure to visit the sticky at the top of this very forum.
     
  7. macrumors newbie

    Joined:
    Jul 13, 2011
    #7
    Am I missing something?

    Hi jNoxx and Roberto,

    I placed the snippet of code you gave here in the appDelegate. I have created the nib file for the login screen. It either I get a blank Window instead of my login screen if I comment out the didFinishLaunchingWithOptions method. If I don't comment this method out, my application goes straight to the split-view screen. Any help would be greatly appreciated. I am totally new to iOS environment so please be have some patience. :)

    Thanks
     
  8. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #8
    Show us what you have tried exactly, and also. Are you sure your viewController is being loaded inside the ModalView? :) Is it showing a modalView.
    Please be a bit more detailed.
     
  9. macrumors newbie

    Joined:
    Jul 13, 2011
    #9
    In the SplitViewAppDelegate.m

    Code:
    -(void)applicationDidFinishLaunching:(UIApplication *)application {
    	NSLog(@"%s", __FUNCTION__);
    	LoginViewController *modalViewLocal = [[[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil] autorelease];
    	[modalViewLocal setModalPresentationStyle:UIModalPresentationFullScreen];
    	[self.splitViewController presentModalViewController:modalViewLocal animated:NO];
    	[window makeKeyAndVisible];
    }
    
    Code:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
        
        self.window.rootViewController = self.splitViewController;
        [self.window makeKeyAndVisible];
        
        return YES;
    } 
    
    I have imported LoginViewController.h into the SplitViewAppDelegate.m file.

    I have left the SplitViewAppDelegate.h file alone from the default generated code. Am I suppose to declare a ModalView in there? If I comment the didFinisLaunchingWithOptions method, it shows that I am executing the applicationDidFinishLaunching method and the "blank" white screen with my NSLog showing that I executed the method. If I don't comment out the didFinishLaunchingWithOptions method, the applicationDidFinishLaunching doesn't execute because NSLog says none but my split-view shows up. I am so confused??? What am I do wrong?

    I have a simple LoginViewController.xib with just a "Login" button. LoginViewController.m and .h have the basic stubbed out code for a UIViewController from xCode.

    I have a basic split-view application. I just wanted to see the login screen before the split-view.

    Thanks
     
  10. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #10
    Choose one of the 2 methods, your gonna use the Options or the one without.. That's the catch in your code I think..
    Try to use the one without the options..

    Code:
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    //DO funky stuff here
    	 self.window.rootViewController = self.splitViewController;
    	[window addSubview:splitViewController.view];
    	LoginScreenController *modalLoginView = [[[LoginScreenController alloc] initWithNibName:@"LoginScreenController" bundle:nil] autorelease];
    	[modalLoginView setModalPresentationStyle:UIModalPresentationFullScreen];
    	[self.splitViewController presentModalViewController:modalLoginView animated:NO];
    	 
    	[window makeKeyAndVisible];
    }
    
    Haven't tested it yet, but should be something like that :)
     
  11. macrumors newbie

    Joined:
    Jul 13, 2011
    #11
    Hey jnoxx, I have tried this but all I got was a window frame with no orientation change on my main splitview(stayed in portrait mode). Do you know of a sample code I can compare against? I just want to see a working version of your example code. By the way, thank you so much for your help.
     
  12. macrumors newbie

    Joined:
    Jul 13, 2011
    #12
    Hi jnoxx, I found the issue. I was loading the splitview with the code.

    Code:
    self.window.rootViewController = self.splitViewController;
    Once I commented out that code, the LoginViewModal was presented and change when clicked login with my method. Thank you so much for your help.
     
  13. jiangxd, Aug 24, 2011
    Last edited: Aug 24, 2011

    macrumors newbie

    Joined:
    Aug 24, 2011
    #13
    hi,jnoxx:
    my code is:
    Code:
    -(void)applicationDidFinishLaunching:(UIApplication *)application{
        [window addSubview:splitViewController.view];
        LoginViewController * modalLoginView=[[[LoginViewController alloc]initWithNibName:@"LoginView" bundle:nil]autorelease];
        [modalLoginView setModalPresentationStyle:UIModalPresentationFullScreen];
        [self.splitViewController presentModalViewController:modalLoginView animated:NO];
        [window makeKeyAndVisible];
    }
    when the app was started,the window was blank... what's wrong with this code? I need your help, thanks.
     
  14. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #14
    Errr, well that all depends, did you set a breakpoint in your LoginView, see if it get's loaded. Does your splitview loads without the modal view? :)
     
  15. macrumors newbie

    Joined:
    Aug 24, 2011
    #15
    hi, thanks for your reply,I will debug that right now :)
     
  16. jiangxd, Aug 24, 2011
    Last edited: Aug 24, 2011

    macrumors newbie

    Joined:
    Aug 24, 2011
    #16
    I added the code below to the LoginViewController.m:
    Code:
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        NSLog(@"LoginView loaded...");
        // Do any additional setup after loading the view from its nib.
    }
    But I didn't see the log message was printed

    Next,I added the code below:
    Code:
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        NSLog(@"init LoginView...");
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
            NSLog(@"init complete...");
        }
        return self;
    }
    the output is:
    2011-08-24 20:41:46.114 Strong OA[580:b603] init LoginView...
    2011-08-24 20:41:46.116 Strong OA[580:b603] init complete...

    could you help me analyze the reasons?
     
  17. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #17
    Yes, you are Initting the UIViewController, which is correct, so that's normal.
    But did your project run, WITHOUT the modalviewController? ;)
    (did you see the actual SplitView)
     
  18. macrumors newbie

    Joined:
    Aug 24, 2011
    #18
    yes,it's running WITHOUT the modalviewController,I didn't see the SplitView displayed either.

    the pic is:
    ipad-1.png
     
  19. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #19
    Well, then I'm quite sure that your modal viewcontorller view outlet is not set ;)
    Is your xib properly wired up, from the login controller?
     
  20. macrumors newbie

    Joined:
    Aug 24, 2011
    #20
    okay,please look at the pic which I uploaded:

    right click the File's Owner:
    ipad2.png

    click the View object,then the Connections Inspector is:
    ipad3.png
     
  21. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #21
    You got me there, There should be something at least going wrong, since I don't have problems at all ;p I tried it myself yesterday, and tadaaa :p It works.
    if u NSLog the pointer, does it contain a Reference to the memory adress, or does it return (null).

    Beside that problem, I see you have a login button on "touch down", didn't you mean "touch up inside"? :p
     
  22. macrumors newbie

    Joined:
    Aug 24, 2011
    #22
    before pop the modal win:
    ipad5.png

    after pop the modal win:
    ipad6.png

    how can I let the modal's direction same with the prior case?

    BTW:I set "supported device orientations"="Landscape Right".
     
  23. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #23
    So you got the Login Modal to work?
    And erm, is your view setted up as Landscape (in the XIB). And you do a return LandscapeRight, Also do a LandscapeLeft :)
    or just set in your project settings your app to only support Left/right, and then set the return type of the - (BOOL) shouldAutorotate bla blah.
    to return YES;
     
  24. macrumors newbie

    Joined:
    Aug 24, 2011
    #24
    thanks!

    it worked! ha! :D
     
  25. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium

Share This Page