首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >navigationController问题

navigationController问题
EN

Stack Overflow用户
提问于 2011-10-02 10:08:17
回答 3查看 732关注 0票数 0

我有以下几点:

代码语言:javascript
复制
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath(NSIndexPath*)indexPath
{

     audiChassisInputViewController = [[myAudiChassisInputViewController alloc] init];    

    [self.navigationController pushViewController:audiChassisInputViewController animated:YES];

    self.navigationController.navigationBarHidden = NO;

    UIBarButtonItem *retourButton = [[UIBarButtonItem alloc] initWithTitle:@"Retour" style:UIBarButtonItemStyleBordered target:self.navigationController action:@selector(popViewControllerAnimated:)]; 
    [self.navigationController.navigationBar.topItem setLeftBarButtonItem:retourButton];
    [self.navigationController.navigationBar.topItem setTitle:@"Chassis Input"];
    [retourButton release];

    [audiChassisInputViewController release];

}

并展示了这个workes...the新视图。

在新观点中:

myAudiChassisInputViewController.h

代码语言:javascript
复制
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    chassisInputTextView.layer.cornerRadius = 15;
    chassisInputTextView.clipsToBounds = YES;
    [chassisInputTextView becomeFirstResponder];

    UIBarButtonItem *okButton = [[UIBarButtonItem alloc] initWithTitle:@"OK" style:UIBarButtonItemStyleBordered target:self action:@selector(chassisOkPressed)];  
    [self.navigationController.navigationBar.topItem setRightBarButtonItem:okButton];
    [okButton release];

}

我没有错误,但是没有正确的酒吧按钮shown.Anyone,知道为什么吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-10-02 10:18:07

更改这一行:

代码语言:javascript
复制
[self.navigationController.navigationBar.topItem setRightBarButtonItem:okButton];

用这一行:

代码语言:javascript
复制
[[self navigationItem] setRightBarButtonItem:okButton];

问题是,在执行viewDidLoad时,导航栏(self.navigationController.navigationBar.topItem)的顶部项仍然指向后视图控制器的导航项。

后视图控制器是在当前顶视图控制器被推到堆栈([[viewControllers objectAtIndex:[viewControllers count] - 2] navigationItem])之前曾经是顶视图控制器的控制器。下面的片段显示导航栏的顶部项如何仍然指向viewDidLoad中的back视图控制器的导航项,仅用于说明目的:

代码语言:javascript
复制
// the view controllers currently on the navigation stack
NSArray *viewControllers = self.navigationController.viewControllers;
// The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.
UIViewController *backViewController = [viewControllers objectAtIndex:[viewControllers count] - 2];
// get the navigation item of the back view controller
UINavigationItem *backNavigationItem = backViewController.navigationItem;
UINavigationItem *topItem = self.navigationController.navigationBar.topItem;
if  (backNavigationItem == topItem) {
    NSLog(@"This gets logged to the console");
}
票数 2
EN

Stack Overflow用户

发布于 2011-10-02 11:44:39

去你的

myAudiChassisInputViewController.m文件

位置跟随代码

代码语言:javascript
复制
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    UIBarButtonItem *retourButton = [[UIBarButtonItem alloc] initWithTitle:@"Retour" style:UIBarButtonItemStyleBordered target:self.navigationController action:@selector(popViewControllerAnimated:)];

    UIBarButtonItem *itemOkey=[[UIBarButtonItem alloc] initWithTitle:@"OK" style:UIBarButtonItemStyleBordered target:self action:@selector(chassisOkPressed)];

    self.navigationItem.rightBarButtonItem=itemOkey;
    self.navigationItem.leftBarButtonItem=retourButton;
}

我有如下所需的有效输出:

希望它对你有帮助。

票数 1
EN

Stack Overflow用户

发布于 2011-10-02 14:50:02

如果您有类的xib文件,那么添加导航控制器并添加导航条,然后在导航栏下面添加UIBarButton。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7625744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档