Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open another view when button is pressed in iOS

Tags:

ios

view

I am completely new to iOS development and I want to load another view when a button is pressed in a present view.

I have created a view based application and following are the codes:

//My file name is poo1

//This is poo1ViewController.h file

#import <UIKit/UIKit.h>
@interface poo1ViewController : UIViewController 
{
 IBOutlet UIButton *fl;
}
@property (nonatomic,retain) UIButton *fl;
-(IBAction) ifl:(id)sender;    
@end

//This is poo1ViewController.m file

#import "poo1ViewController.h"
@implementation poo1ViewController
@synthesize fl;
-(IBAction) ifl:(id) sender {
}

In the poo1ViewController.xib I have added a button and linked it with File's Owner using Interface Builder.

Now I have added another view to this class called as flip.xib an just added a label inside it.

The thing I want is, when I will press the fl button, the fl button will call the method ifl and which in return should call the second view, i.e. flip.xib.

How will I do that, how can I make the ifl method to load flip.xib view ?

like image 372
Samrat Mazumdar Avatar asked Jun 28 '11 16:06

Samrat Mazumdar


1 Answers

UIViewController* flipViewController = [[UIViewController alloc] initWithNibName:@"flip.xib" bundle:[NSBundle mainBundle]];
[self.view addSubview:flipViewController.view];

EDIT:

UIViewController* flipViewController = [[UIViewController alloc] initWithNibName:@"flip" bundle:[NSBundle mainBundle]];
[self.view addSubview:flipViewController.view];

Now click on flip.xib, click on the File's Owner on the left hand side of the design area, and change the class to UIViewController. Now CTRL drag from File's Owner icon to the View icon right below it and select the IBOutlet View.

like image 64
bdparrish Avatar answered Oct 19 '22 23:10

bdparrish