-1

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:

enter image description here

Maulik
  • 19,348
  • 14
  • 82
  • 137

4 Answers4

3

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];
Piyush Dubey
  • 2,416
  • 1
  • 24
  • 39
1

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];
rptwsthi
  • 10,094
  • 10
  • 68
  • 109
1

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

Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
0
- (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.

nsinvocation
  • 7,559
  • 3
  • 41
  • 46