简体   繁体   English

如何在UItoolbar中检查UIbarbutton类

[英]How to check UIbarbutton class in UItoolbar

I am using a toolbar with UIbarButton items, and i had given tags for that, In one scenario i need to get all the subviews of the Toolbar and disable one Button 我正在使用带有UIbarButton项的工具栏,并且为此提供了标签,在一种情况下,我需要获取工具栏的所有子视图并禁用一个按钮

                    for (id toolBarSubView in [self.topToolBar subviews]) {

                        NSLog(@"toolBarSubView details %@",toolBarSubView);

                        if ([toolBarSubView isKindOfClass:[UIBarButtonItem class]] && [toolBarSubView tag] == 103) {
                            UIButton* backButton = (UIButton*)toolBarSubView;
                            backButton.enabled = YES;
                        }
                        else if([toolBarSubView isKindOfClass:[UIBarButtonItem class]] && [toolBarSubView tag] == 102)
                        {

                            UIButton* navigationTitle = (UIButton*)toolBarSubView;
                            navigationTitle.enabled = NO;
                        }
                        else if([toolBarSubView isKindOfClass:[UIBarButtonItem class]] && [toolBarSubView tag] == 104)
                        {
                            UIButton* infoButton = (UIButton*)toolBarSubView;
                            infoButton.enabled = NO;
                        }

I am using above code, i am trying to find the class name like this [toolBarSubView isKindOfClass:[UIBarButtonItem class] 我正在使用上面的代码,我试图找到像这样的类名[toolBarSubView isKindOfClass:[UIBarButtonItem class]

But the condition is failing none of the condition is success, Which class i have to in the console it is some thing like this 2013-09-13 12:15:35.943 Receipts[1544:60b] toolBarSubView details > 2013-09-13 12:15:35.945 Receipts[1544:60b] toolBarSubView details > 2013-09-13 12:15:35.947 Receipts[1544:60b] toolBarSubView details > 但是条件失败了,没有一个条件是成功,我必须在控制台中选择哪个类,就像这样的事情2013-09-13 12:15:35.943 Receipts [1544:60b] toolBarSubView详细信息> 2013-09-13 12:15:35.945收据[1544:60b] toolBarSubView详细信息> 2013-09-13 12:15:35.947收据[1544:60b] toolBarSubView详细信息>

If you put UIButton in UIToolBar instead of UIBarButtonItem in UIToolBar, by default UIButton comes under UIBarButtonItem. 如果将UIButton而不是UIToolBar中的UIBarButtonItem放在UIToolBar中,则默认情况下,UIButton在UIBarButtonItem下。 Then you can check like this, 然后您可以像这样检查

if([toolBarSubView isKindOfClass:[UIButton class]] && [toolBarSubView tag] == 10)
{}

If you want to check particular UIBar button item in UIToolbar,do like this 如果要检查UIToolbar中的特定UIBar按钮项,请执行以下操作

NSArray *barButtons = [self.topToolBar items];
    for(UIBarButtonItem *myBarButton in barButtons)
    {
        NSLog(@"%d",myBarButton.tag);
        if(myBarButton.tag == 103)
        {}
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM