删除导航按钮
嘿,我编写了一个类 (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我设法使用以下方法解决了这个问题:
我的思维冻结了,并在按钮实际创建之前使用了上面的语句:-(
I managed to solve it using:
I had a mind freeze and was using the above statement before the button had actually when created :-(
将 NavigationItem 的属性“hidesBackButton”设置为 yes 会更容易:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UINavigationItem_Class/Reference/UINavigationItem.html#//apple_ref/occ/cl/UINavigationItem
It would be easier to set the NavigationItem's property "hidesBackButton" to yes:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UINavigationItem_Class/Reference/UINavigationItem.html#//apple_ref/occ/cl/UINavigationItem
另一个需要考虑的选择是禁用该按钮,直到您希望它起作用为止。它将可见,但变暗。
Another option to consider is to disable the button until you want it to function. It will be visible, but dimmed.
要从导航栏中删除按钮,只需为按钮分配标签并编写以下代码
To Remove Button from navigation bar just assign tag to button and write a below code