iPhoneシミュレーターでビューを切り替えるのに問題があります。ビューを前後に切り替えることができるコードを記述しましたが、シミュレーターで実行したときに、アプリがビューを前方に切り替えるだけで、切り替えることができないことがわかりました。後ろ姿。コード内の問題を追跡できません。誰かが私のコードの問題を突き止めるのを手伝ってくれたらありがたいです。
私のコードは:
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
前もって感謝します。