从 NavigationItem 中删除 BarButtonItem

发布于 2024-10-09 09:35:14 字数 381 浏览 0 评论 0原文

我正在创建一个使用导航控制器的应用程序。我已经完成了从导航栏中添加和删除 UIBarButtonItem 的操作。我的左侧有后退按钮,右侧有一个名为(更多)的附加按钮。

现在我的要求是,当我单击“更多”时,我需要在导航栏左侧添加一个“关闭”按钮,并且“后退”按钮应该隐藏。我也完成了这个。

问题是在删除我正在使用的关闭按钮时:

self.navigationItem.leftBarButtonItem = nil;

它也删除了我的后退按钮。我需要保留后退按钮,只想删除该按钮。

我不知道我是否正确,我需要编写用于显示后退按钮返回的代码。或者有什么方法可以在单击“更多”按钮或“关闭”本身时仅删除“关闭”按钮。

谢谢

I am creating an app in which I am using navigation Controller. I had done with adding and removing UIBarButtonItem from the navigation Bar. I have back button at my left side and a additional button at right side named (MORE).

Now my requirement is when I click on the MORE I need to add a CLOSE button on the left side of Navigation Bar and Back button should be hide. I am done with this too.

The problem is while removing the CLOSE button I am using like:

self.navigationItem.leftBarButtonItem = nil;

It removes my back button too. I need to keep back button and only want to remove the button.

I don't know whether I am right and I need to write code for displaying back button back. or is there any way by which I can remove only CLOSE button on the click of MORE button or CLOSE itself.

Thanks

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

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

发布评论

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

评论(1

夏夜暖风 2024-10-16 09:35:14

如果您点击“更多”按钮,则“后退”按钮应该隐藏,并且“更多”应该添加到导航栏的左侧,因此您可以执行以下操作:

-(void) moreButtonClicked{

[self.navigationItem setLeftBarButtonItem:nil animated:NO];
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"CLOSE" style:UIBarButtonItemStyleBordered target:self action:@selector (closeButtonClicked:)];
self.navigationItem.leftBarButtonItem = closeButton;
[closeButton release];

}

当您想要删除“关闭”按钮并将“后退”按钮设置在之前的位置时,请尝试这样做:

[self.navigationItem setLeftBarButtonItem:nil animated:NO];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"BACK" style:UIBarButtonItemStyleBordered target:self action:@selector (backButtonClicked:)];
self.navigationItem.leftBarButtonItem = backButton;
[backButton release];

If you tap on MORE button, then BACK button should be hide and MORE should be added on left side of NavBar so you can do this as:

-(void) moreButtonClicked{

[self.navigationItem setLeftBarButtonItem:nil animated:NO];
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"CLOSE" style:UIBarButtonItemStyleBordered target:self action:@selector (closeButtonClicked:)];
self.navigationItem.leftBarButtonItem = closeButton;
[closeButton release];

}

when you want to remove your CLOSE button and set your BACK button at previous place then try this as:

[self.navigationItem setLeftBarButtonItem:nil animated:NO];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"BACK" style:UIBarButtonItemStyleBordered target:self action:@selector (backButtonClicked:)];
self.navigationItem.leftBarButtonItem = backButton;
[backButton release];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文