Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 17, 2011, 04:46 AM   #1
roberto.vigo
macrumors newbie
 
Join Date: Feb 2011
open a modalViewController at application launch

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 by roberto.vigo; Feb 21, 2011 at 11:19 AM. Reason: Resolved
roberto.vigo is offline   0 Reply With Quote
Old Feb 17, 2011, 05:09 AM   #2
jnoxx
macrumors 65816
 
jnoxx's Avatar
 
Join Date: Dec 2010
Location: Aartselaar // Antwerp // Belgium
Quote:
Originally Posted by roberto.vigo View Post
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
jnoxx is offline   0 Reply With Quote
Old Feb 17, 2011, 05:38 AM   #3
roberto.vigo
Thread Starter
macrumors newbie
 
Join Date: Feb 2011
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!
roberto.vigo is offline   0 Reply With Quote
Old Feb 17, 2011, 09:18 AM   #4
jnoxx
macrumors 65816
 
jnoxx's Avatar
 
Join Date: Dec 2010
Location: Aartselaar // Antwerp // Belgium
Quote:
Originally Posted by roberto.vigo View Post
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!
No problem, that's what i'm here for
jnoxx is offline   0 Reply With Quote
Old Feb 21, 2011, 04:11 AM   #5
roberto.vigo
Thread Starter
macrumors newbie
 
Join Date: Feb 2011
How to add the "resolved" prefix to the thread?

thanks
Roberto
roberto.vigo is offline   0 Reply With Quote
Old Feb 21, 2011, 11:13 AM   #6
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by roberto.vigo View Post
How to add the "resolved" prefix to the thread?
Make sure to visit the sticky at the top of this very forum.
__________________
dejo is offline   0 Reply With Quote
Old Jul 13, 2011, 02:54 PM   #7
vnle74
macrumors newbie
 
Join Date: Jul 2011
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 is offline   0 Reply With Quote
Old Jul 14, 2011, 03:19 AM   #8
jnoxx
macrumors 65816
 
jnoxx's Avatar
 
Join Date: Dec 2010
Location: Aartselaar // Antwerp // Belgium
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.
jnoxx is offline   0 Reply With Quote
Old Jul 14, 2011, 09:31 AM   #9
vnle74
macrumors newbie
 
Join Date: Jul 2011
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
vnle74 is offline   0 Reply With Quote
Old Jul 15, 2011, 04:05 AM   #10
jnoxx
macrumors 65816
 
jnoxx's Avatar
 
Join Date: Dec 2010
Location: 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
jnoxx is offline   0 Reply With Quote
Old Jul 18, 2011, 09:35 AM   #11
vnle74
macrumors newbie
 
Join Date: Jul 2011
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 is offline   0 Reply With Quote
Old Jul 18, 2011, 09:50 AM   #12
vnle74
macrumors newbie
 
Join Date: Jul 2011
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.
vnle74 is offline   0 Reply With Quote
Old Aug 24, 2011, 06:07 AM   #13
jiangxd
macrumors newbie
 
Join Date: Aug 2011
Quote:
Originally Posted by jnoxx View Post
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 by jiangxd; Aug 24, 2011 at 06:10 AM. Reason: add something
jiangxd is offline   0 Reply With Quote
Old Aug 24, 2011, 06:44 AM   #14
jnoxx
macrumors 65816
 
jnoxx's Avatar
 
Join Date: Dec 2010
Location: Aartselaar // Antwerp // Belgium
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?
jnoxx is offline   0 Reply With Quote
Old Aug 24, 2011, 07:52 AM   #15
jiangxd
macrumors newbie
 
Join Date: Aug 2011
Quote:
Originally Posted by jnoxx View Post
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 is offline   0 Reply With Quote
Old Aug 24, 2011, 08:22 AM   #16
jiangxd
macrumors newbie
 
Join Date: Aug 2011
Quote:
Originally Posted by jnoxx View Post
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 by jiangxd; Aug 24, 2011 at 08:46 AM.
jiangxd is offline   0 Reply With Quote
Old Aug 24, 2011, 08:49 AM   #17
jnoxx
macrumors 65816
 
jnoxx's Avatar
 
Join Date: Dec 2010
Location: Aartselaar // Antwerp // Belgium
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)
jnoxx is offline   0 Reply With Quote
Old Aug 24, 2011, 08:56 AM   #18
jiangxd
macrumors newbie
 
Join Date: Aug 2011
Quote:
Originally Posted by jnoxx View Post
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:
Click image for larger version

Name:	ipad-1.png
Views:	18
Size:	29.7 KB
ID:	300244
jiangxd is offline   0 Reply With Quote
Old Aug 24, 2011, 11:12 AM   #19
jnoxx
macrumors 65816
 
jnoxx's Avatar
 
Join Date: Dec 2010
Location: Aartselaar // Antwerp // Belgium
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?
jnoxx is offline   0 Reply With Quote
Old Aug 24, 2011, 08:54 PM   #20
jiangxd
macrumors newbie
 
Join Date: Aug 2011
Quote:
Originally Posted by jnoxx View Post
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:
Click image for larger version

Name:	ipad2.png
Views:	46
Size:	112.3 KB
ID:	300318

click the View object,then the Connections Inspector is:
Click image for larger version

Name:	ipad3.png
Views:	22
Size:	43.0 KB
ID:	300319
jiangxd is offline   0 Reply With Quote
Old Aug 25, 2011, 03:15 AM   #21
jnoxx
macrumors 65816
 
jnoxx's Avatar
 
Join Date: Dec 2010
Location: 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 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"?
jnoxx is offline   0 Reply With Quote
Old Aug 25, 2011, 04:20 AM   #22
jiangxd
macrumors newbie
 
Join Date: Aug 2011
before pop the modal win:
Click image for larger version

Name:	ipad5.png
Views:	11
Size:	33.2 KB
ID:	300361

after pop the modal win:
Click image for larger version

Name:	ipad6.png
Views:	14
Size:	30.4 KB
ID:	300362

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

BTW:I set "supported device orientations"="Landscape Right".
jiangxd is offline   0 Reply With Quote
Old Aug 25, 2011, 04:52 AM   #23
jnoxx
macrumors 65816
 
jnoxx's Avatar
 
Join Date: Dec 2010
Location: 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;
jnoxx is offline   0 Reply With Quote
Old Aug 25, 2011, 05:59 AM   #24
jiangxd
macrumors newbie
 
Join Date: Aug 2011
Quote:
Originally Posted by jnoxx View Post
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!
jiangxd is offline   0 Reply With Quote
Old Aug 25, 2011, 08:11 AM   #25
jnoxx
macrumors 65816
 
jnoxx's Avatar
 
Join Date: Dec 2010
Location: Aartselaar // Antwerp // Belgium
Ofcourse it does
Good luck.
jnoxx is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Application Launch adds Blue Tint to Screen bpletcher MacBook Pro 8 Nov 10, 2014 06:11 PM
Can't open application nocakeforyou Mac Applications and Mac App Store 4 Jun 18, 2013 05:10 PM
cant open the application ProfilerPlus 2.3 macimux OS X 4 Mar 27, 2013 03:47 PM
New Application Launch By Power App ademcalvin iPhone and iPod touch Apps 0 Sep 29, 2012 02:27 AM
Web application link application launch puzzle lancewan Mac Applications and Mac App Store 0 Jun 21, 2012 09:37 AM

Forum Jump

All times are GMT -5. The time now is 02:32 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC