在iPhone中,UIButton可能无法响应enumerateobjectsusingblock? [英] UIButton may not respond to enumerateobjectsusingblock, in iPhone?

查看:126
本文介绍了在iPhone中,UIButton可能无法响应enumerateobjectsusingblock?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用中使用BCGenieEffect。我从github下载演示示例。 https://github.com/Ciechan/BCGenieEffect

I want to use BCGenieEffect in my app. I download demo example from github. https://github.com/Ciechan/BCGenieEffect

在此示例中使用了xib,并且xib使用了4个UIButtons。我想在不使用xib的情况下使用此代码,仅用于一个按钮。我不想拖动我的视图,这就是我删除该代码的原因。

In this example xib is used and 4 UIButtons is used with xib. I want to use this code without xib and only for one button. I dont want to drag my view thats why I remove that code.

我有一个UIButton:

I have one UIButton:

UIButton *Pop_Hidebtn = [[UIButton alloc]initWithFrame:CGRectMake(290, 5, 15, 15)];
Pop_Hidebtn.backgroundColor = [UIColor clearColor];
[Pop_Hidebtn setImage:[UIImage imageNamed:@"close.png"] forState:UIControlStateNormal];

Pop_Hidebtn.titleLabel.textColor = [UIColor blueColor];
[Pop_Hidebtn addTarget:self action:@selector(Hidden_pop:)  forControlEvents:UIControlEventTouchUpInside];  
[popup_View addSubview:Pop_Hidebtn];


-(void)Hidden_pop:(UIButton *)sender{
    [self genieToRect:sender.frame edge:BCRectEdgeBottom];
}


// I modified this and it says-> UIButton may not respond to enumerateobjectsusingblock
// And Crash 

- (void) genieToRect: (CGRect)rect edge: (BCRectEdge) edge {
    NSTimeInterval duration = 3.0;

    CGRect endRect = CGRectInset(rect, 5.0, 5.0);

    [help_Button enumerateObjectsUsingBlock:^(UIButton *button, NSUInteger idx, BOOL   *stop) { 
        help_Button.enabled = NO;
    }];


    if (self.viewIsIn) {

        [popup_View_under2 genieOutTransitionWithDuration:duration startRect:endRect      startEdge:edge completion:^{
            popup_View_under2.userInteractionEnabled = YES;

            [help_Button enumerateObjectsUsingBlock:^(UIButton *button, NSUInteger idx,  BOOL  *stop) {
                help_Button.enabled = YES;

            }];
        }];

    } else {
        popup_View_under2.userInteractionEnabled = NO;

        //UIButton may not respond to enumerateobjectsusingblock
        // Crash on this line
        [popup_View_under2 genieInTransitionWithDuration:duration destinationRect:endRect      destinationEdge:edge completion: ^{
            [help_Button enumerateObjectsUsingBlock:^(UIButton *button, NSUInteger idx,  BOOL *stop) {
                button.enabled = YES;
            }];
        }];
    }

    self.viewIsIn = ! self.viewIsIn;
}

我该如何解决这个问题?

how can I solve this problem?

推荐答案

- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block

NSArray的实例方法 NSOrderedSet NSSet 类。因此,如果你根据我假设的实例 UIButton 调用该方法,它将无效。

Is an instance method of the NSArray, NSOrderedSet and NSSet classes. So it won't work if you call that method on what I assume is an instance of UIButton.

方法旨在用于枚举集合中的对象。所以你必须以这种方式将你的按钮放在 NSArray (或 NSMutableArray )中:

That method is intended to be used to enumerate objects in a collection. So you'd have to put your button in an NSArray (or NSMutableArray) in this way:

[myButtons enumerateObjectsUsingBlock:^(UIButton *aButton, NSUInteger idx, BOOL   *stop) { 
    aButton.enabled = NO;
}];

将为 myButtons 数组,接收对象本身(在这种情况下,它将被转换为 UIButton * ),所述对象的索引和指向<$ c的指针$ c> BOOL ,你可以用来提前退出循环。

The block will be called for every object in the myButtons array, receiving the object itself (in this case, it will be casted to UIButton *), the index of said object, and a pointer to a BOOL, that you can use to exit the loop early.

注意,因为你说你只会使用一个按钮,你为什么不删除那些方法调用只是使用

Note that since you said you're going to use just one button, why don't you remove that methods call and just use

helpButton.enabled = YES;

没有枚举?

这篇关于在iPhone中,UIButton可能无法响应enumerateobjectsusingblock?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆