problem with showing modalviewcontroller in landscape mode in iphone? - iphone

my application consist of a landscape view where i want to put a modalview but the problem is with modalview. it doesn't get load on presenting it.. code is:
--------------------code here----------------------
UIViewController *modalViewController = [[UIViewController alloc] init];
modalViewController.view = modelView1;
[self presentModalViewController:modalViewController animated:NO];
[self performSelector:#selector(hideSplash) withObject:nil afterDelay:5.0];
plz kindly help me with this....

The problem with ur code is that u are initializing it with alloc-init, without any nib name. Now when call:
[self presentModalViewController:modalViewController animated:NO];
The view will load itself by calling its loadview method, and u have definitely nothing in that. So if u do want to initialize in the same manner, just try to move the line of code:
modalViewController.view = modelView1;
after:
[self presentModalViewController:modalViewController animated:NO];
like:
[self presentModalViewController:modalViewController animated:NO];
modalViewController.view = modelView1;
I think this would work then.
Hope this helps.
thanks,
madhup

Related

error when i am calling next view controller

i am getting an error when i am calling next view controller, i want to call a view controller that a action continue .this screen will come appear first time only when we run first time.
controller is not going next view.
-(void)viewDidLoad
{
welcomePage *temp = [[welcomePage alloc]initWithNibName:#"welcomePage" bundle:nil];
[self presentViewController:temp animated:YES completion:^(void){}];
}
Warning: Attempt to present on whose view is not in the window hierarchy!
Try this one..
You change the code in Appdelegate.m didFinishLaunchingWithOptions method like this
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = nav;
And in your ViewDidLoad method like this..
welcomePage *temp = [[welcomePage alloc]initWithNibName:#"welcomePage" bundle:nil];
[self.navigationController presentViewController:temp animated:YES completion:nil];
For dismissing viewcontroller you can write following code in welcomepage button action
-(IBAction)dismiss:(id)sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
use this code
-(void)viewDidLoad
{
welcomePage *temp = [[welcomePage alloc]initWithNibName:#"welcomePage" bundle:nil];
[self presentViewController:temp animated:YES completion:nil];
}
That error means you are trying to present a modal view controller from a view controller that is not currently in the screen.
If You are using Storyboard : Use this
instantiateViewControllerWithIdentifier
UIViewController objController = [self.storyboard instantiateViewControllerWithIdentifier:#"StoryBoard Id"];
[self presentViewController:objController animated:YES completion:nil];
To Set Storybaord ID , Check Here .
This error means that you are trying to present 'welcome page' from a view that is not on the screen yet.
Knowing that simply moving the code to the viewDidAppear method doesn't work for you, what you can try to do is this:
-(void)viewDidAppear
{
[self presentWelcome];
}
- presentWelcome {
welcomePage *temp = [[welcomePage alloc]initWithNibName:#"welcomePage" bundle:nil];
[self presentViewController:temp animated:YES completion:^(void){}];
}
What happens here is that when the view appears (so when it is in the view hierarchy), the controller starts a function that calls the other viewController. hope this solves your problem.
Hope this helps you!

Two UIViews for one ViewController

I'm not sure how to do this. So I originally had a ViewController that had one .xib, with one main view. I present it like this:
DogViewController *dvc = [[DogViewController alloc] initWithNibName:#"DogViewController" bundle:nil];
dvc.modalPresentationStyle = UIModalPresentationFormSheet;
dvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:dvc animated:YES];
[dvc release];
So that works fine. However now from a button press in the DogViewController.xib, I want to dismiss the current form sheet, and show another form sheet with some additional questions before proceeding. So I started by adding another view to in my original .xib of DogViewController, then got stuck in the logic of how to dismiss the first one, and show the second one. I'm assuming I need some outlet to the new view in the same .xib, but from there I'm lost. Thanks.
The way to do this would be to set it up with a UINavigationController as Mathiew mentions. However, if you really want to transition between two views on one view controller, you can refer to this sample code from Apple:
http://developer.apple.com/library/ios/#samplecode/ViewTransitions/Introduction/Intro.html
The code uses ImageViews to demonstrate the effect but I don't see why you can't use views instead :)
You can add a view within the other view in front of all of the other objects and just use its hidden property to control whether it's shown or not.
Why don't you use a navigation controller in your modal view, create another xib and do a [self.navigationController pushViewController:secondViewController animated:YES];
If you have a good reason, you can set a second view outlet secondView and use code like
UIView* superview = [self.view superview];
[self.view removeFromSuperView];
[superview addSubview:self.secondView];
Very simple solution is to hold reference to MainViewController and call methods on it that swap between two view controllers.
Like this:
#implementation MainViewController
- (void)showDogViewController {
[self dismissModalViewControllerAnimated:YES];
DogViewController *dvc = [[DogViewController alloc] initWithNibName:#"DogViewController" bundle:nil];
dvc.modalPresentationStyle = UIModalPresentationFormSheet;
dvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
dvc.mainViewController = self;
[self presentModalViewController:dvc animated:YES];
[dvc release];
}
- (void)showCatViewController {
[self dismissModalViewControllerAnimated:YES];
CatViewController *cvc = [[CatViewController alloc] initWithNibName:#"CatViewController" bundle:nil];
cvc.modalPresentationStyle = UIModalPresentationFormSheet;
cvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
cvc.mainViewController = self;
[self presentModalViewController:cvc animated:YES];
[dvc release];
}
}
#end
#implementation DogViewController
- (void)showCatViewController {
[mainViewController showCatViewController]
}
#end
#implementation CatViewController
- (void)showDogViewController {
[mainViewController showDogViewController]
}
#end

xib not connected to controller?

I am extremely new to iPhone development, so please forgive this post if it seems naive. I am trying to simply add a subview to my current view (if this is the best way to open a new screen on iPhone). Here is my code:
QuickCalcController *aViewController = [[QuickCalcController alloc]
initWithNibName:#"QuickCalcController" bundle:nil];
aViewController.view.frame = CGRectMake(0, 100, quickCalcController.view.frame.size.width, quickCalcController.view.frame.size.height);
[self.view addSubview: quickCalcController.view];
self.view.bounds = quickCalcController.view.bounds;
The problem is, when this code gets called, the view shown is not QuickCalcController.xib. It is MainView.xib. The file's owner is QuickCalcController... am I missing something?
Thanks in advance.
You should just ask the mainViewController to present the QuickCalcController:
QuickCalcController *aViewController = [[QuickCalcController alloc]
initWithNibName:#"QuickCalcController" bundle:nil];
[self presentModalViewController:aViewController animated:YES];
[aViewController release], aViewController = nil;
Then to dimiss QuickCalcController just call [self dismissModalViewControllerAnimated:YES]; in QuickCalcController.

pushViewController call from uiview

let me explain you my problem:
I have an UIViewController with 2 UIViews.
I have a button in one of my UIView and i call a methode from my UIViewController.
[controller actionMainSettings];
And this is the methode:
-(void)actionMainSettings{
MainSettings *mainController = [[MainSettings alloc] initWithNibName:#"MainSettings" bundle:nil];
[self.navigationController pushViewController:mainController animated:YES];
[[self navigationController] setNavigationBarHidden:YES animated:NO];
[mainController release];
}
MainSettings is an UIVewController...
and nothing happen...
When i put my button in my UIVIewController ([self.view addSubview:buttonSettings];) it's ok but i want to put it in another UIView.
Can someone explain me what happen?
thx
I am not very sure about this but you could try super.navigationController instead of self.
Also, from the look of your code, I would assume it's a settings view. I would recommend that you use [self presentModalView:yourView animated:YES]. You can look at the UIView documentation for a range of animations.

How to do a login screen?

I have this working but I don't think it is working correctly so I just wanted to get your feedback. I am trying to display a screen that has two buttons - one that takes you to a login screen and the the allows you to register.
II am testing in the appDelegate if they are logged in and if they aren't I am showing the signLogIN view.
signLogIN = [[LoginOrSignUPViewController alloc] init];
signLogIN.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
signLogIN.tabBarController = mainAPPTabBarController;
signLogIN.mainWindow = window;
[window addSubview:[signLogIN view]];
//[signLogIN release];
(I release in the appDelegate dealloc - if I release here it blows up when they select to either login or register).
I did try doing:-
[mainAPPTabBarController presentModalViewController:signLogIN animated:NO];
But it made no difference.
Curiously I can see that the dealloc in LoginOrSignUPViewController is called straight away - why is that? I can't tell where it is being called from.
From LoginOrSignUPViewController I am then displaying the login screen by doing:-
[self retainCount] = 1
LoginViewController *logINVC = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
logINVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
logINVC.delegate = self;
logINVC.tabBarController = self.tabBarController;
[self presentModalViewController:logINVC animated:YES];
[logINVC release];
now [self retainCount] = 3 = why did it go to three????
As you can see there is a delegate that calls back to the signLogIn view to close the view as follows:-
[self retainCount] = 3
[mainWindow bringSubviewToFront:tabBarController.view];
tabBarController.selectedIndex = 0;
[self.view removeFromSuperview];
[self dismissModalViewControllerAnimated:NO];
[self release];
[self retainCount] = 3 -- still 3 it never goes away
So here is my main problem LoginOrSignUPViewController never goes away it just sits behind my main view. The only line that makes any difference is the [mainWindow bringSubViewToFront. Does anyone have any ideas as to how to make the LoginOrSignUPViewController disappear?
Thanks very much
Cheryl
Have you tried this in your view controller's viewDidLoad:
LoginOrSignUPViewController *signLogIN = [[LoginOrSignUPViewController alloc] init];
[self presentModalViewController:signLogIN animated:NO];
[signLogIn release];