I am trying to create an application in Xcode that will switch to a new view when the phone is rotated from one orientation to another.
Here is the code for the switchviewcontroller.h file:
#import <UIKit/UIKit.h>
@interface SwitchViewController : UIViewController {
}
-(IBAction)switchview:(id)sender;
@end
And here is the code for the switchviewcontroller.m file:
#import "SwitchViewController.h"
#import "secondview.h"
@implementation SwitchViewController
-(IBAction)switchview:(id)sender {}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if((fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight))
{
[[secondview alloc] initWithNibName:@"secondview" bundle:[NSBundle mainBundle]];
}
}
It works in the iPhone simulator without errors, but when I rotate it does not load the new view. To start, I think I need an application for opening in landscape mode, which I don’t know how to do, but it won’t work anyway, and I think that it has something with the "initWithNibName" part in the code, I have .xib files, not .nib files. Can someone help me with these two things? Thank.
source
share