在iPhone中,UIButton可能不响应enumerateobjectsusingblock?
我想在我的应用程序中使用BCGenieEffect。我从github下载了演示示例 在本例中,使用了xib,4个UIB按钮与xib一起使用。我想在没有xib的情况下使用这段代码,并且只针对一个按钮。我不想拖动我的视图,这就是我删除该代码的原因 我有一个按钮:在iPhone中,UIButton可能不响应enumerateobjectsusingblock?,iphone,ios,objective-c,xcode,ipad,Iphone,Ios,Objective C,Xcode,Ipad,我想在我的应用程序中使用BCGenieEffect。我从github下载了演示示例 在本例中,使用了xib,4个UIB按钮与xib一起使用。我想在没有xib的情况下使用这段代码,并且只针对一个按钮。我不想拖动我的视图,这就是我删除该代码的原因 我有一个按钮: UIButton *Pop_Hidebtn = [[UIButton alloc]initWithFrame:CGRectMake(290, 5, 15, 15)]; Pop_Hidebtn.backgroundColor = [UICol
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;
}
我怎样才能解决这个问题
- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block
是NSArray
、NSOrderedSet
和NSSet
类的实例方法。因此,如果在我假设的UIButton
实例上调用该方法,它将不起作用
该方法用于枚举集合中的对象。因此,您必须以以下方式将按钮放入NSArray
(或NSMutableArray
)中:
[myButtons enumerateObjectsUsingBlock:^(UIButton *aButton, NSUInteger idx, BOOL *stop) {
aButton.enabled = NO;
}];
将为myButtons
数组中的每个对象调用块,接收对象本身(在这种情况下,它将被强制转换为UIButton*
)、所述对象的索引以及指向BOOL
的指针,您可以使用该指针提前退出循环
请注意,既然您说过只使用一个按钮,为什么不删除该方法调用并使用它呢
helpButton.enabled = YES;
没有枚举?如果我删除-(void)enumerateObjectsUsingBlock:(void(^)(id obj,nsu整数idx,BOOL*stop))块并仅使用helpButton.enabled=YES;那么视图没有最小化。如何在2 GeneiTransitionWithDuration下写这一行[popup\u view\u:duration destinationRect:endRect destinationEdge:edge completion:如果我删除或注释这一行/*[popup\u view\u under2 GeneiTransitionWithDuration:duration destinationRect:endRect destinationEdge:edge completion:^{[help_Button enumerateObjectsUsingBlock:^(UIButton*按钮,NSU整数idx,BOOL*停止){Button.enabled=YES;}];}]*/
[popup_View_under2 GeneiTransitionWithDuration:duration destinationRect:endRect destinationEdge:edge完成:^{helpButton.enabled=YES;}]
应该可以。不起作用,先生。您能为新手制作一个演示吗?这对新开发人员有很大帮助。因为我很难解决这个问题。如果您能为我们制作一个演示并与我分享。谢谢。。。