删除导航按钮

发布于 2024-10-19 10:10:17 字数 1169 浏览 4 评论 0原文

嘿,我编写了一个类 (A),它继承了一些功能,包括导航按钮的实现。 A 类同时具有查看和编辑模式,我只想在处于编辑模式时显示按钮。到目前为止,我还无法删除此按钮,而且我真的不想创建另一个类只是为了编辑。

其他类也继承了这个功能,所以我真的不想和父类搞乱。

我用来创建按钮的代码如下:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];    
UIImage *buttonImage = [UIImage imageNamed:@"button.png"];

[button addTarget:self 
               action:@selector(buttonPressed:) 
     forControlEvents:UIControlEventTouchUpInside];

button.bounds = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);

[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setTitle:NSLocalizedString(@"BUTTON", @"") 
            forState:UIControlStateNormal];

LPRBSLabel *buttonLabel = [[LPRBSLabel alloc] initWithStyle:UICustomeButtonTitle];
[button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, -5.0, 0.0)];

button.titleLabel.font = buttonLabel.font;
[button setTitleColor:buttonLabel.textColor forState:UIControlStateNormal];
[buttonLabel release];

UIBarButtonItem *barLeftInfoButton = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = barLeftInfoButton;
[barLeftInfoButton release];

Hey, I've written a class (A) which inherits some functionality including an implementation of a navigation button. Class A has both a view and edit mode, I want to only show the button when am in edit mode. So far I've not been able to remove this button and I don't really want to create to another class just for edit.

Also other classes inherit this functionality so I don't really want to be messing about with parent.

The code that I use to create the button is below:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];    
UIImage *buttonImage = [UIImage imageNamed:@"button.png"];

[button addTarget:self 
               action:@selector(buttonPressed:) 
     forControlEvents:UIControlEventTouchUpInside];

button.bounds = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);

[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setTitle:NSLocalizedString(@"BUTTON", @"") 
            forState:UIControlStateNormal];

LPRBSLabel *buttonLabel = [[LPRBSLabel alloc] initWithStyle:UICustomeButtonTitle];
[button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, -5.0, 0.0)];

button.titleLabel.font = buttonLabel.font;
[button setTitleColor:buttonLabel.textColor forState:UIControlStateNormal];
[buttonLabel release];

UIBarButtonItem *barLeftInfoButton = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = barLeftInfoButton;
[barLeftInfoButton release];

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

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

发布评论

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

评论(4

高速公鹿 2024-10-26 10:10:17

我设法使用以下方法解决了这个问题:

self.navigationItem.leftBarButtonItem = nil;

我的思维冻结了,并在按钮实际创建之前使用了上面的语句:-(

I managed to solve it using:

self.navigationItem.leftBarButtonItem = nil;

I had a mind freeze and was using the above statement before the button had actually when created :-(

轮廓§ 2024-10-26 10:10:17

另一个需要考虑的选择是禁用该按钮,直到您希望它起作用为止。它将可见,但变暗。

self.navigationItem.leftBarButtonItem.enabled = NO;

Another option to consider is to disable the button until you want it to function. It will be visible, but dimmed.

self.navigationItem.leftBarButtonItem.enabled = NO;
汹涌人海 2024-10-26 10:10:17

要从导航栏中删除按钮,只需为按钮分配标签并编写以下代码

[[self.navigationController.navigationBar viewWithTag:0106] removeFromSuperview];

To Remove Button from navigation bar just assign tag to button and write a below code

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