![](/img/trans.png)
[英]iPhone SDK: Switching to one view then back to previous view errors
[英]Cannot switching view back in 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
提前致謝。
在第二個視圖中使用它
-(IBAction)switchview:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
@implementation secondview
-(IBAction)switchview:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.