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

rickjackson

macrumors newbie
Original poster
Dec 24, 2010
25
0
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
 
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.
 
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.

Hey jnoxx thanks for reply. I will implement as what u have said and get back to you on this.
 
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.......
 
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 ;)
 
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 ;)

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
 
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 :)
 
Code:
Modal1 *modalTradeShowListing = [[Modal1 alloc] init];
...
===> MODALSCREENPOPUP.M

Is your class name Modal1 or MODALSCREENPOPUP?

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)
Why do you think it's bad coding? The View Controller Programming Guide for iOS even states:
It is worth noting that a view controller presented modally can itself present another view controller modally.
 
Last edited:
===> MODALSCREENPOPUP.M

Code:
- (void) OpenTradeShowListingPopup
{
	[COLOR="red"][B][self dismissModalViewControllerAnimated:YES];[/B][/COLOR]
	
	TradeShowListing *modalTradeShowListing = [[TradeShowListing alloc] init];
	
	[modalTradeShowListing setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
	[modalTradeShowListing setModalPresentationStyle:UIModalPresentationFullScreen];
	
	[self presentModalViewController:modalTradeShowListing animated:YES];
	
    //[modalTradeShowListing release];
}
Try removing the dismissal of the first modal view (highlighted in red) and let us know what happens.
 
Try removing the dismissal of the first modal view (highlighted in red) and let us know what happens.

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];
}
 
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.
 
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.

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
 
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 :)
 
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.

<Code snipped for brevity>
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.

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.
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.