iPhone UINavigationController 问题(按钮、标题不可见)

发布于 2024-10-01 14:52:16 字数 483 浏览 1 评论 0原文

我的 UINavigationController 有两个问题。

问题 1

在初始视图中,我以编程方式添加了一个 rightBarButtonItem。

当我将导航视图推到右侧时,一切正常,并且出现一个带有上一个视图标题的后退按钮。

当我点击后退按钮时,我就回来了。但后来这个按钮就消失了。但它并没有真正消失,它只是不可见,因为它仍然可以被单击。

问题2

当我推送右侧的viewController时,无法设置标题。我在推送视图之前尝试过

myViewController.title = @"someTitle";

,并且也在 viewController 内部尝试过,

self.title = @"someTitle";

但这里没有任何效果。

I have two problems with the UINavigationController.

Problem 1

On the initial view I programmatically added a rightBarButtonItem.

When I push the navigationView to the right, everything works right and it appears a back button with the title of the previous view.

When I click the back button, I get back. But then this button is gone. But it's not really gone, it's just invisible, because it can still be clicked.

Problem 2

When I push the viewController on the right, I can't set the title. I tried it before pushing the view with

myViewController.title = @"someTitle";

and I tried it also inside of the viewController with

self.title = @"someTitle";

but nothing works here.

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

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

发布评论

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

评论(2

凶凌 2024-10-08 14:52:16

我发现问题:

我正在向导航栏添加自定义背景图像。不知何故,这张图片超出了标题/按钮。

因此,如果您想实现自定义背景图像,不要使用此:

UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
[backgroundImage setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"headerBg" ofType:@"png"]]];
[navigationController.navigationBar insertSubview:backgroundImage atIndex:0];
[backgroundImage release];

而是使用此:

@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed: @"headerBg.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end

I found the problem:

I was adding a custom background image to the navigationBar. Somehow this image got over the title / button.

So if you ever want to implement a custom background image, don't user this:

UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
[backgroundImage setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"headerBg" ofType:@"png"]]];
[navigationController.navigationBar insertSubview:backgroundImage atIndex:0];
[backgroundImage release];

But instead, use this:

@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed: @"headerBg.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
小嗲 2024-10-08 14:52:16

问题一:
听起来很奇怪。确实没有答案:-/

问题 2:
您能否提供更多关于此的代码片段,例如您尝试设置标题的整个方法主体?

Problem 1:
Sounds odd. Don't really have an answer for that :-/

Problem 2:
Can you provide some more code snippets on this, like the whole method bodies where you tried to set the title?

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