Here is the current code I have:
(IBAction)signup:(id)sender {
SignUp *signUp = [[SignUp alloc] init];
signUp.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:signUp animated:YES];
I am only getting an error on the bottom line. It reads: "No visible #interface for 'loginView' delcares the selector 'presentViewController:animated.'
Here is what I do not understand... I interfaced loginView as a child of the UIViewController class... This is where presentViewController is declared. Why is it telling me it can't find anything and how do I fix it?
Thank you ahead of time!
Are you sure that presentViewController:animated: is declared in UIViewController? In my docs it's listed as presentViewController:animated:completion:. You can have an empty completion block if you don't have anything to do there.
[self presentViewController:signup animated:YES completion:^(){}];
Related
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!
im trying to load another nib of a UIViewController after expected time. Everything does work but wenn i load the UIViewController i get a exception when it is called. I'm doing it that way:
UIViewController *overView = [[UIViewController alloc] initWithNibName:#"overView2" bundle:nil];
[super presentViewController:overView animated:YES completion:nil];
i also tried to insert [NSBundle mainBundle] instead of "nil" but the exception still occures.
When i push the UIViewController in following was, no exception occures but after the first view is removed nothing happends:
[self.parentViewController addChildViewController:overView];
i were searching long time but couldn't find a solution...
SOLUTION
I just found the mistake.
I imported the H-File of the UIViewController in the M-File where i wanted to load the new View.Than i created a new object and passed it through.
overView2 *overView = [[overView2 alloc] init];
[self presentViewController:overView animated:YES completion:nil];
sorry, I'm new to objectiv-c...maybe will help some other beginners too :P
A standard implementation of presenting a view controller is:
[self presentViewController:overView animated:YES completion:nil];
Unless I'm missing something. Is there any more information that you can give?
I'm having a little predicament switching between views, here.
Alright, so, I have this view controller class in my iPhone project called "BaseViewController," which is the default, which has a button called "GoToNextView." I added another ViewController to the storyboard called "NextViewController," and then I created another custom view controller class called "NextViewController." Under the inspector window for NextViewController on the storyboard I changed its custom class to "NextViewController;" I'm assuming everything should be hooked up, now. When I click on the "GoToNextView" button, though, the application stops with a SIGABRT message.
Here's the code for my button click action in the BaseViewController class.
- (IBAction)Transition_Next:(id)sender
{
nextViewController = [[NextViewController alloc]
initWithNibName:#"SecondView"
bundle:[NSBundle mainBundle]];
[self.view addSubview:nextViewController.view];
}
What might I be doing wrong, here?
Thanks in advance...
You can use:
- (IBAction)Transition_Next:(id)sender
nextViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:nextViewController animated:YES];
}
Instead of your code and it should work! Hope that helps!
You can use [self.navigationController pushViewController:nextViewController animated:NO]; or if you don't have a navigation controller, you may use
[self presentModalViewController:nextViewController animated:NO]; instead of [self.view addSubview:nextViewController.view];
I have the following Objective-C code:
MainMenu *main= [[MainMenu alloc] initWithNibName:nil bundle:nil];
[[self navigationController]pushViewController:main animated:YES];
NSLog(#"hello");
I have a class called 'MainMenu' with a corresponding header file and xib file. No matter what I do, it simply won't show. I have confirmed that the code gets to the above, because of the NSLog('hello').
I've been pulling my hair out for hours now and I simply cannot get to the bottom of it.
I hope someone can help,
Edit - still having problems...
Here are some screenshots of my project setup:
Ok, so I tried this:
MainMenu *main= [[MainMenu alloc] initWithNibName:nil bundle:nil];
[[self navigationController]pushViewController:main animated:YES];
[self.view addSubview:main.view];
But it still doesn't work...
Many thanks in advance,
The fact that initWithNibName is nil should not be the problem because if it is given nil it looks for a nib with the exact name of the class.
Two things:
1) Make sure you have run a clean recently and make sure that file is correctly being loaded.
2) Make sure navigationController is not nil, if it is then you need to make sure you make a navigation controller if you are not intending on using a navigation controller, consider using:
- (void)presentModalViewController:(UIViewController *)modalViewController
animated:(BOOL)animated
Why are you setting the nibName to nil? If the name of the nib is MainMenu, then you want:
MainMenu *main= [[MainMenu alloc] initWithNibName:#"MainMenu" bundle:nil];
[self.navigationController pushViewController:main animated:YES];
[main release];
Are you sure that you have a UINavigationController in order to push a new view?
Hope that Helps!
Dont pull your hair just look at your code closely: You have nil in your initWithNibName. Whats MainMenu is it a viewController or what ? and place your correct nib for your to get Hello.
Updated as asked :
MainMenu *main= (MainMenu *)[MainMenu alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:main];
[self.navigationController presentModalViewController:nav animated:YES];
NSLog(#"hello");
I guess the issue is that you do not have a navigation controller set up .Try to present the view controller by
[self presentModalViewController:main animated:YES];
Verify that the object owner is in fact MainMenu and the view is connected.
In the MainMenu NIB, select File's Owner and the click on the Identity Inspector. Class should match your VC class name.
Then select the main View in your NIB and click on the Connections Inspector. The view outlet should be connected to your File's Owner.
If those are both set correctly, then post some more surrounding code. Notable point, if those are both set,
MainMenu * main= [[MainMenu alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:main animated:YES];
will load the correct NIB and display it.
What are you seeing? Another point if MainMenu is a subclass of some other VC with a NIB you will have to change the base class' init to override the default behavior, for example:
self = [super initWithNibName:nibNameOrNil == nil ? #"BaseViewController" : nibNameOrNil bundle:nibBundleOrNil]
But in that case you would have to specific the NIB that will override the base view controller's.
Post more code and let us know what you are seeing when you run.
I am trying (from my 3rd child in the heirachy) to load the root view with the following. This does not work and I get the following error when the below code is run.
-[DetailViewController clickButton:]: unrecognized selector sent to instance 0x1161e00'
Code:
MapViewController *dvController = [[MapViewController alloc] initWithNibName:#"MapView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
This exact same code works on other views, any idea how to debug this.
The code you wrote to create the MapViewController and push it onto the view controller stack is correct.
The unrecognized selector error is telling you that you are sending are attempting to call a method (named clickButton:) that does not exist.
I would suspect a spelling error. I take it that you most likely have a button defined that calls the code to create the new view. The method should look like this:
-(void) clickButton: (id) sender {
MapViewController *dvController = [[MapViewController alloc] initWithNibName:#"MapView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
I would check that you have the ":(id) sender" part. I have made the mistake before of implementing a -(void) clickButton {} method, but had the message actually sending a parameter as well.
If you have created the button programatically and set the target as clickButton, make sure the clickButton method is present
The clickButton method (according to the error) should take in an argument. So the definition of the method will be
(IBAction)clickButton:(id)sender;
If you have mapped the IBAction to an event in IB, you can omit the :(id)sender part
To load the root view controller from any view in a navigation-based application, use
[[self navigationController:popToRootViewControllerAnimated:YES];