I have a problem with switching the views in iPhone simulator.I had written a code that can switch views back and forward but now when I had run it in the simulator I found that the app only switches the view forward but I am unable to switch the view back. I am unable to trace out the problem in my code. Will be thankful if anyone had helped me trace out the problem with my code.
My code is :
SwitchingViewsViewController.h
#import <UIKit/UIKit.h>
@interface SwitchingViewsViewController : UIViewController
{
}
-(IBAction)switchback:(id)sender;
@end
SwitchingViewsViewController.m
#import "SwitchingViewsViewController.h"
#import "secondview.h"
@interface SwitchingViewsViewController ()
@end
@implementation SwitchingViewsViewController
-(IBAction)switchback:(id)sender
{
secondview *second = [[secondview alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end
secondview.h
#import <UIKit/UIKit.h>
@interface secondview : UIViewController
{
}
-(IBAction)switchview:(id)sender;
@end
secondview.m
#import "secondview.h"
#import "SwitchingViewsViewController.h"
@interface secondview ()
@end
@implementation secondview
-(IBAction)switchview:(id)sender
{
SwitchingViewsViewController *second = [[SwitchingViewsViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
Thanks in advance.
use this in second view