How do I call the SecondViewController on Xcode? - iphone

I'm new to programming on Xcode and can't really find out how to call the SecondViewController window by pressing a button. The button is called Ingredients; I tried entering "-(IBAction)Ingredients:(id)sender; in the ViewController.h and but then saw that there was the FirstViewController.h and SecondViewController.h, same with First and second ViewControllers.
Anyways, what I wanted to do was be able to click the "Ingredients" button and make it go to a completely different window, with a different background, and other texts as the first one. I'm not sure if I'm explaining myself correctly :(. Let me try an Image:

First of all, get some basic knowledge about Objective C. Go to Apple developer website and you will get tons of tutorials & sample codes to learn.
Now, for your question:-
In firstViewController.m
First import SecondViewController.h
On button click:-
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];

As I can see you are not using story board so simply call:
FLSecondViewController *object = [[FLSecondViewController alloc] initWithNibName:#"FLSecondViewController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:object animated:YES];

Why go for another window? a View controller may be enough,set up a navigation controller and push the second viewcontroller.
a sample tutorial on navigation controller

- (IBAction)Ingredients:(id)sender
{
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self presentModalViewController:secondViewController animated:YES];
}
edited: Typical an iOS app has only one window which acts as a container for views, so you work most of time only with views. Change one view with another depend on desired content to be presented.

Related

Same view on navigation in ios6

In my application i use the following code to navigate to a new view on receiving a click, It is working properly on iOS5. However, When i try with ios6 it is showing the current view and Is not goin to the next view. Do i need to change anything for ios6 in this code.
please help me to solve.
scoreview *sview=[[scoreview alloc] initWithNibName:#"scoreview" bundle:nil];
[self.navigationController pushViewController:sview animated:YES];
Try these lines:
scoreview *sview=[[scoreview alloc] initWithNibName:#"scoreview" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:sview animated:YES];
Can you please check your view is Correctly connected with UIInterfaceBuilder

presenting a modal view controller

I have this same piece of code in two different parts of my app.
In one section it is executed perfectly, and in the other it is completely ignored. I've put in a breakpoint and watched the program go through each line of this code without loading the next xib/class it is supposed to.
Here is the code:
UIViewController *nextController = [[ClassNameViewController alloc] initWithNibName:#"MatchingView" bundle:nil];
[nextController performSelector:#selector(setDelegate:) withObject:self];
[self presentModalViewController:nextController animated:YES];
Any ideas why this might be getting ignored and not presenting my viewController?
Try using ..
[self.navigationController presentModalViewController:nextController animated:YES];
I had this code in viewDidLoad and moving it to viewDidAppear made it work.

How to Animate iPhone New Screen towards Left

I am new bee in iPhone and just started development in it.
Learning a lot because of friends like you!
I just learnt how to go to another screen from current screen and i Did well due to tutorials from Internet.
But now the problem is when new screen comes up it animates from Bottom to Up and when we click DONE button to close the screen it goes from Up to Down. I have seen many applications in iPhone that animate the new screen from Right to Left and again from Left to Right.
What Piece of code do i need to add into the following to animate it toward left.
Please guide me Friends
MainScreen *screen = [[MainScreen alloc] initWithNibName:#"MainScreen" bundle:[NSBundle mainBundle]];
self.mainScreen = screen;
[self presentModalViewController:mainScreen animated:YES];
There are four different ModelTransitionsFor View Controllers.
You can set those for
screen.modalTransitionStyle = UIModalTransitionStylePartialCurl;
There are 3 other Styles you can check on Apple Site Link
If you need to do something like Navigation Style. you need to push your view controller to navigation stack.
[self.navigationController pushViewController:screen animated:YES];
Instead of this
[self.navigationController presentModalViewController:yourView animated:YES];
use this
[self.navigationController pushViewController:yourView animated:YES];
If you have Navigation based app then replace code with below.
MainScreen *screen = [[MainScreen alloc] initWithNibName:#"MainScreen" bundle:[NSBundle mainBundle]];
self.mainScreen = screen;
[self.navigationController pushViewController:screen animated:YES];
There are few modal view transitional styles available. Check apples documentation on this.
Also there are few uiviewtransitionanimation styles also described neatly in apple's guide.

How come presentModalViewController is not working the second time?

I am using a tab based application that shows a presentModalViewController called "overview" that has 2 buttons on it .
In order to call it I am using the following code in app delegate:
Overview *overview = [[Overview alloc] initWithNibName:#"Overview" bundle:nil];
[self.tabBarController presentModalViewController:overview animated:YES];
When overview shows up, it has a button called that gets clicked and I am using the following code:
-(IBAction) btnLoginPressed{
[self dismissModalViewControllerAnimated:YES]; //get rid of view
Login *login = [[Login alloc] initWithNibName:#"Login" bundle:nil];
[self.tabBarController presentModalViewController:login animated:YES];
[login release];
}
However the login prsentModalViewController never shows up. Can someone explain why and what I can do to show it?
Thanks
When you present a modal view controller, you do it from the view controller currently in the view.
Assuming your second modal display of a view controller is happening in Overview.m change your code to the following:
-(IBAction) btnLoginPressed {
Login *login = [[Login alloc] initWithNibName:#"Login" bundle:nil];
[self presentModalViewController:login animated:YES];
[login release];
}
You don't need to dismiss Overview first, and in fact you shouldn't as it the animations won't work in conjunction with each other.
When you ultimately dismiss login (or however deep you want to go), you send dismissModalViewController:animated: as high up as you need to. To get back to the tab bar's controller use:
[self.tabBarController dismissModalViewController:animated]
It would be well beyond the scope of your question and the time I have to answer but you should take some time and really study the docs on implementing View Controllers. I definitely recommend following Apple's code style guidelines as one suggestion to make your code much more readable (e.g. overviewViewController vs overview). It's also clear you're just learning so keep at it.

iPhone SDK: Navigation is causing crash

My app is crashing when I navigate two view controllers in my application. For example, if I do this sequence:
RootController
ViewControllerA
ViewControllerB
ViewControllerA
My app crashes.
It crashes when I pressed the back button in ViewControllerB. So, It seems like it is with two or more ViewControllers being pushed. Each by themselves work.
I don't know why.
This is the code I am using to invoke new views.
salesViewController *anotherViewController = [[salesViewController alloc] initWithNibName:#"salesView" bundle:nil];
//confirmViewController *anotherViewController = [[confirmViewController alloc] initWithNibName:#"confirmView" bundle:nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
Thanks in advance.
Good news is that your code to create new views is just fine. Bad news is that it's somewhere else. I found this conversation on the net that seems to be a similar issue.