gpt4 book ai didi

cocoa-touch - UINavigationBar 右键不显示

转载 作者:可可西里 更新时间:2023-11-01 04:42:49 24 4
gpt4 key购买 nike

我通过通知使用以下功能在我的 UINavigationBar 上加载一个右键,即使我可以追踪到该按钮并验证它已分配,它也没有显示...有什么想法吗?

编辑 2011 年 4 月 6 日下午 2:42

所以,有趣的是...宽度总是报告为 0.0...

- (void)showRightBarButton:(id)sender
{
NSLog(@"Showing button");
UIBarButtonItem *button = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(showPI:)];
[button setTitle:@"This Button"];
self.navigationItem.rightBarButtonItem = button;
//[[self.navigationItem rightBarButtonItem] setWidth:50];
NSLog(@"Button width is %f.", self.navigationItem.rightBarButtonItem.width);
[button release];
}

最佳答案

[self.view setNeedsDisplay];

你是对的。不需要那条线。就代码的其余部分而言,我看不出它有什么问题。到目前为止,我唯一想到的是 self 不是当前显示的 View Controller ,或者您缺少导航 Controller 。也许您自己创建了 UINavigationBar 而不是使用导航 Controller ?

无论如何,为了更容易调试,我建议如下:

- (void)showRightBarButton:(id)sender
{
NSLog(@"Showing button");
UIBarButtonItem *button = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(showPI:)];
self.navigationItem.rightBarButtonItem = button;
[button release];
}

编辑: 宽度没有意义。除非您自己指定,否则它始终为 0.0。

问题是您在错误的位置添加了按钮。您不应该将按钮添加到导航 Controller 的导航项,而是添加到导航 Controller 当前显示的 Controller 的导航项。

关于cocoa-touch - UINavigationBar 右键不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5569965/

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