0

我在 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

第二视图.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

提前致谢。

4

2 回答 2

1

在第二个视图中使用它

-(IBAction)switchview:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
于 2012-12-18T02:29:53.623 回答
0
@implementation secondview


-(IBAction)switchview:(id)sender
{
    [self dismissModalViewControllerAnimated:YES];
}
于 2012-12-18T03:44:30.727 回答