gpt4 book ai didi

iphone - 无法在 iPhone 中切换回 View

转载 作者:行者123 更新时间:2023-11-29 04:14:18 24 4
gpt4 key购买 nike

我在 iPhone 模拟器中切换 View 时遇到问题。我编写了一个可以前后切换 View 的代码,但现在当我在模拟器中运行它时,我发现该应用程序只能向前切换 View ,但我无法将 View 切换回来。我无法找出代码中的问题。如果有人帮助我找出代码的问题,我将不胜感激。

我的代码是:

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

第二 View .h

#import <UIKit/UIKit.h>

@interface secondview : UIViewController
{

}
-(IBAction)switchview:(id)sender;
@end

第二 View .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

提前致谢。

最佳答案

在第二个 View 中使用它

-(IBAction)switchview:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}

关于iphone - 无法在 iPhone 中切换回 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13925368/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com