如何避免iPhone中Bar Button项目的多次触摸?

发布于 2024-09-25 22:39:20 字数 545 浏览 2 评论 0原文

我已经创建了工具栏并在该工具栏中设置了 UIBarbuttonItem。当我单击工具栏按钮时,我刚刚删除了一个自定义视图。我想避免多次触摸栏按钮项目,因为有时用户会多次单击栏按钮项目。(这种情况仅发生一段时间)。

这是我的示例代码,

     UIBarButtonItem *closeBtn =[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(action)] autorelease];

    toolBar.items = [NSArray arrayWithObjects:space,closeBtn,nil];

     -(void) action
     {
         [customView removeFromSuperview];
     }

所以我想在单击工具栏中的栏按钮时避免多次触摸。我如何检测栏按钮是否被选择?那么我该如何避免这个问题呢? 请帮帮我。

谢谢!

I have created tool bar and set the UIBarbuttonItem in that tool bar.When i clicks the bar button, i have just removed one custom view. I want to avoid the multiple touches of the bar button items, because sometimes the user clicks the bar button items more than one.( It happens some time only).

Here my sample code,

     UIBarButtonItem *closeBtn =[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(action)] autorelease];

    toolBar.items = [NSArray arrayWithObjects:space,closeBtn,nil];

     -(void) action
     {
         [customView removeFromSuperview];
     }

So i want to avoid the multiple touch, when clicks the bar button in the tool bar. And how can i detect to the bar button is select?. So how can i avoid this problem?
Please help me out.

Thanks!

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

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

发布评论

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

评论(1

蓝眼睛不忧郁 2024-10-02 22:39:20

有多种可能的方法,但其中一种是将按钮设置为禁用。你需要稍微改变一下你的行动方法。

 -(void) action:(id)sender
 {
     if ([sender isKindOfClass:[UIBarItem class]]) {
         [sender setEnabled:NO];
     }
     [customView removeFromSuperview];
 }

There are several possible approaches, but one is to set the button to disabled. You'll need to change your action method a bit.

 -(void) action:(id)sender
 {
     if ([sender isKindOfClass:[UIBarItem class]]) {
         [sender setEnabled:NO];
     }
     [customView removeFromSuperview];
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文