iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – UINavigationBar后退按钮在某些设备或模拟器上显示“Back”标题,在其他设备或模拟器上显示以前的视图控制器标题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个带有导航栏的应用程序,可以从一个视图控制器导航到下一个视图控制器.
当导航到某些模拟器和设备上的下一个视图控制器时,后退按钮标题是“后退”,并且在某些模拟器和设备上,后退按钮标题是第一个视图控制器的标题.

我真的很想明白为什么?

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

这是代码

App代表

#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;
}

第一视图控制器

#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;
}

第二视图控制器

#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";
}

解决方法

当您设置当前视图控制器的标题时,当您移动到下一个视图控制器时,它将自动设置在导航栏中的“后退”位置.如果您没有设置当前视图控制器的标题,那么iOS会自动显示BACk标题.

要设置视图控制器的标题,请使用以下代码

self.title = @"<title>";

我想你会从解释中得到这个.

大佬总结

以上是大佬教程为你收集整理的ios – UINavigationBar后退按钮在某些设备或模拟器上显示“Back”标题,在其他设备或模拟器上显示以前的视图控制器标题全部内容,希望文章能够帮你解决ios – UINavigationBar后退按钮在某些设备或模拟器上显示“Back”标题,在其他设备或模拟器上显示以前的视图控制器标题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。