gpt4 book ai didi

ios - UINavigationBar 后退按钮在某些设备或模拟器上显示 "Back"标题,在其他设备或模拟器上显示之前的 View Controller 标题

转载 作者:可可西里 更新时间:2023-11-01 05:21:36 27 4
gpt4 key购买 nike

我有一个带有导航栏的应用程序,可以从一个 View Controller 导航到下一个 View Controller 。在某些模拟器和设备上导航到下一个 View Controller 时,后退按钮标题是“返回”,而在某些模拟器和设备上,后退按钮标题是第一个 View Controller 的标题。

我很想知道为什么?

这不是更改后退按钮上的文本的问题。问题是在某些模拟器和设备上我看到了“后退”标题,而在某些模拟器和设备上我看到了前一个 Controller 的标题。在 20 多个模拟器和设备上进行了测试。

代码如下:

应用委托(delegate)

#import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"

@interface AppDelegate ()
@property (nonatomic, strong) UINavigationController *navigationController;
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
FirstViewController *firstViewController = [[FirstViewController alloc]
initWithNibName:nil
bundle:nil];

self.navigationController = [[UINavigationController alloc]
initWithRootViewController:firstViewController];

self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen]bounds]];

self.window.rootViewController = self.navigationController;

self.window.backgroundColor = [UIColor whiteColor];

[self.window makeKeyAndVisible];


return YES;
}

第一个 View Controller

#import "FirstViewController.h"
#import "SecondViewController.h"

@interface FirstViewController ()
@property (nonatomic, strong) UIButton *btnDisplaySecondViewController;
@end

@implementation FirstViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}


-(void)performDisplaySecondViewController:(id)paramSender{
SecondViewController *secondControllrt = [[SecondViewController alloc]
initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:secondControllrt
animated:YES];
}


- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"First Controller";

self.btnDisplaySecondViewController = [UIButton
buttonWithType:UIButtonTypeSystem];

[self.btnDisplaySecondViewController
setTitle:@"Display Seconf View Controller"
forState:UIControlStateNormal];

[self.btnDisplaySecondViewController sizeToFit];

self.btnDisplaySecondViewController.center = self.view.center;

[self.btnDisplaySecondViewController addTarget:self
action:@selector(performDisplaySecondViewController:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:self.btnDisplaySecondViewController];


UIImageView *imageView =
[[UIImageView alloc]
initWithFrame:CGRectMake(0.0, 0.0, 100.0f, 40.0f)];

imageView.contentMode = UIViewContentModeScaleAspectFit;

UIImage *image = [UIImage imageNamed:@"ios7_0135"];

[imageView setImage:image];

self.navigationItem.titleView = imageView;
}

第二个 View Controller

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}


- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Second Controller";
}

最佳答案

当您设置当前 View Controller 的标题时,当您移动到下一个 View Controller 时,它将自动设置在导航栏中的 Back 位置。如果您没有设置当前 View Controller 的标题,那么 iOS 会自动显示 Back 标题。

要设置 View Controller 的标题,请使用以下代码:

self.title = @"<title>";

我想你会从解释中明白这一点。

关于ios - UINavigationBar 后退按钮在某些设备或模拟器上显示 "Back"标题,在其他设备或模拟器上显示之前的 View Controller 标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21579298/

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