Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

roberto.vigo

macrumors newbie
Original poster
Feb 17, 2011
5
0
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
 
Last edited:

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
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

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
 

roberto.vigo

macrumors newbie
Original poster
Feb 17, 2011
5
0
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!
 

vnle74

macrumors newbie
Jul 13, 2011
4
0
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
 

vnle74

macrumors newbie
Jul 13, 2011
4
0
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
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
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 :)
 

vnle74

macrumors newbie
Jul 13, 2011
4
0
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.
 

vnle74

macrumors newbie
Jul 13, 2011
4
0
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.
 

jiangxd

macrumors newbie
Aug 24, 2011
8
0
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 :)

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.
 
Last edited:

jiangxd

macrumors newbie
Aug 24, 2011
8
0
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? :)

hi, thanks for your reply,I will debug that right now :)
 

jiangxd

macrumors newbie
Aug 24, 2011
8
0
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? :)

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?
 
Last edited:

jiangxd

macrumors newbie
Aug 24, 2011
8
0
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)

yes,it's running WITHOUT the modalviewController,I didn't see the SplitView displayed either.

the pic is:
ipad-1.png
 

jiangxd

macrumors newbie
Aug 24, 2011
8
0
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?
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
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
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
 

jiangxd

macrumors newbie
Aug 24, 2011
8
0
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".
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
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;
 

jiangxd

macrumors newbie
Aug 24, 2011
8
0
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;

thanks!

it worked! ha! :D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.