Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c Can';t设置视图控制器的后栏按钮项的标题_Objective C_Uinavigationcontroller_Uibarbuttonitem_Xcode4.5_Osx Mountain Lion - Fatal编程技术网

Objective c Can';t设置视图控制器的后栏按钮项的标题

Objective c Can';t设置视图控制器的后栏按钮项的标题,objective-c,uinavigationcontroller,uibarbuttonitem,xcode4.5,osx-mountain-lion,Objective C,Uinavigationcontroller,Uibarbuttonitem,Xcode4.5,Osx Mountain Lion,我正在使用一个具有导航控制器的应用程序进行培训,用户可以在两个视图控制器之间切换。 根视图控制器类称为ViewController,这就是我如何以编程方式在我的应用程序委托中添加导航控制器的方法: self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; navController= [[UINavigationController alloc]initWithRoot

我正在使用一个具有导航控制器的应用程序进行培训,用户可以在两个视图控制器之间切换。
根视图控制器类称为ViewController,这就是我如何以编程方式在我的应用程序委托中添加导航控制器的方法:

self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
navController= [[UINavigationController alloc]initWithRootViewController: viewController];
self.window.rootViewController= navController;
这是导航控制器:

@property (strong, nonatomic) UINavigationController* navController;
第二个视图控制器称为SecondViewController。每当用户单击工具栏按钮项时,我都会按下它:

self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle: @"Second View" style: UIBarButtonItemStylePlain target: self action: @selector(switchView:)];
这是执行的选择器:

- (void) switchView : (id) sender
{
    if(!nextController)
    {
        nextController= [[SecondViewController alloc]initWithNibName: @"SecondViewController" bundle: nil];
    }
    [self.navigationController pushViewController: nextController animated: YES];
}
然后,在第二个视图中,控制器会自动出现一个标题为“后退”的按钮,切换到第一个视图。这对我来说很好,但我想设置标题和样式。因此,我正在尝试更改标题:

self.navigationItem.backBarButtonItem.title= @"First View";
但没什么可做的,标题还是“回来”,我该怎么改呢


另外,我不是采用了错误或无效的方法,对吗?

尝试使用此方法更改按钮标题。初始化并添加您自己的LeftBarButtonim并隐藏stock back按钮

UIBarButtonItem* backBtn =  [[UIBarButtonItem alloc] initWithTitle:@"BUTTON_NAME" style:UIBarButtonItemStyleDone target:self action:@selector(backAction)];

self.navigationItem.leftBarButtonItem = backBtn;
self.navigationItem.hidesBackButton = YES;
如果可以的话,你会想隐藏原来的后退按钮,只需要做一个后退动作,这个动作可以是使用popViewcontrollerAnimated函数的(如果你一开始就打开了viewcontroller)


尝试更改按钮标题。初始化并添加您自己的LeftBarButtonim并隐藏stock back按钮

UIBarButtonItem* backBtn =  [[UIBarButtonItem alloc] initWithTitle:@"BUTTON_NAME" style:UIBarButtonItemStyleDone target:self action:@selector(backAction)];

self.navigationItem.leftBarButtonItem = backBtn;
self.navigationItem.hidesBackButton = YES;
如果可以的话,你会想隐藏原来的后退按钮,只需要做一个后退动作,这个动作可以是使用popViewcontrollerAnimated函数的(如果你一开始就打开了viewcontroller)


如果在
viewDidLoad
中设置
ViewController
类的
title
属性,当将
SecondViewController
按到堆栈上时,该字符串将显示为后退按钮的文本。

如果在
viewDidLoad
中设置
ViewController
类的
title
属性,当您将
SecondViewController
按到堆栈上时,该字符串将显示为后退按钮的文本。

you make my day you make my day