0
我在切換iPhone模擬器中的視圖時遇到了問題。我編寫了一個可以切換視圖的代碼,但現在當我在模擬器中運行它時,我發現應用程序只切換前進的觀點,但我無法將視圖切換回來。我無法找到我的代碼中的問題。如果有人幫助我用我的代碼找出問題,會很感激。無法將視圖切換回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
在此先感謝。
你怎麼知道得這麼遠嗎?你是否確認了 - 當你期望他們是--switchview和-switchback都被調用?也許更重要的是,你是否意識到這些方法都推動新模態視圖控制器?假設這些被稱爲你似乎試圖建立一個更深層的模態。您可能希望頂級控制器自行解散。 – Jonah
是的,jonah是對的 –
如果你有解決方法養成接受答案的習慣。 –