更改以编程方式创建的导航栏上的 autoresizingMask

发布于 2024-11-08 22:29:12 字数 1488 浏览 6 评论 0原文

所以我有一个基于视图的应用程序,其中我需要一个带有表格视图的页面,并且我想要在其上方有一个导航栏以返回。我以编程方式添加了以下内容:

-(IBAction)switchToTableView; {

    tableView *table = [[tableView alloc] initWithNibName:@"tableView" bundle:nil];
    UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: table];
    table.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [table release];
    [self presentModalViewController: navControl animated:YES];
    [navControl release];
}

然后在我实现的 tableview 类的 viewDidLoad 中:

- (void)viewDidLoad 
{
    self.tableView.rowHeight = 70.f;

    UIBarButtonItem *back = [[UIBarButtonItem alloc]
                             initWithTitle:@"Back"
                             style:UIBarButtonItemStyleDone
                             target:self
                             action:@selector(switchToHome)];
    self.navigationItem.leftBarButtonItem = back;

    UIBarButtonItem *map = [[UIBarButtonItem alloc]
                            initWithTitle:@"Map"
                            style:UIBarButtonItemStyleDone
                            target:self
                            action:@selector(switchBacktoFindArt)];
    self.navigationItem.rightBarButtonItem = map;
    [map release];

    [super viewDidLoad];
}

添加所需的按钮。现在,所有这些都工作得很好,但现在我正在浏览我的应用程序并允许方向更改,我在这方面遇到了麻烦,因为我无法更改 IB 中的 autoresizingMask。整个表格视图页面的大小调整得很好,除了导航栏从上到下变得非常瘦。我希望它保持相同的高度。我如何设置适当的掩码,甚至访问 IB 外部的导航栏?

So I have a view-based app in which I need one page with a tableview and I wanted a navigation bar above it to go back. I added this programmatically with:

-(IBAction)switchToTableView; {

    tableView *table = [[tableView alloc] initWithNibName:@"tableView" bundle:nil];
    UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: table];
    table.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [table release];
    [self presentModalViewController: navControl animated:YES];
    [navControl release];
}

Then in the viewDidLoad of the tableview class I implemented:

- (void)viewDidLoad 
{
    self.tableView.rowHeight = 70.f;

    UIBarButtonItem *back = [[UIBarButtonItem alloc]
                             initWithTitle:@"Back"
                             style:UIBarButtonItemStyleDone
                             target:self
                             action:@selector(switchToHome)];
    self.navigationItem.leftBarButtonItem = back;

    UIBarButtonItem *map = [[UIBarButtonItem alloc]
                            initWithTitle:@"Map"
                            style:UIBarButtonItemStyleDone
                            target:self
                            action:@selector(switchBacktoFindArt)];
    self.navigationItem.rightBarButtonItem = map;
    [map release];

    [super viewDidLoad];
}

to add the needed buttons. Now, all of this worked great, but now that I'm going through my app and allowing for orientation changes, I'm having trouble with this one since I can't change the autoresizingMask in IB. The whole tableview page resizes nicely except the navigation bar becomes very skinny top-to-bottom wise. I'd like it to stay the same height. How do I go about setting the appropriate Masks or even accessing the navigation bar outside of IB?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

指尖微凉心微凉 2024-11-15 22:29:12

我想你可以使用这样的东西来禁用高度变化:

navControl.navigationBar.autoresizingMask ^= UIViewAutoresizingFlexibleHeight

但是如果你像这样使用它的内部结构,UINavigationController 可能真的会变得不稳定。令我惊讶的是,导航栏尚未调整到适当的令人愉悦的高度,就像默认情况下应该做的那样。 (感觉代码中的其他地方可能有其他问题,但我必须查看更多信息才能找到答案)。

I suppose you can play with things like this to disable height changes:

navControl.navigationBar.autoresizingMask ^= UIViewAutoresizingFlexibleHeight

But a UINavigationController might really get wonky if you play around with its internals like that. I'm surprised that the nav's bar isn't already resizing to an appropriately pleasing height, like it's supposed to do by default. (It feels like something else might be wrong elsewhere in your code, but I'd have to see more to find out).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文