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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With