iOS 禁用以编程方式创建的按钮,直到功能完成
<p><p>您好,提前感谢您的耐心和帮助:)</p>
<p>这是我正在做的事情:
- 我以编程方式创建多个调用相同功能的按钮</p>
<p>而我想要完成的是:
- 按下按钮后,我希望通用功能运行并禁用所有按钮,以便在执行第一次调用期间不会再次调用该功能。第一次通话结束后,我想重新启用按钮。</p>
<p>这是我创建按钮的方法:</p>
<pre><code>@interface ViewController ()
{
UIButton *button;
}
@end
@implementation ViewController
- (void)viewDidLoad {
;
// Do any additional setup after loading the view, typically from a nib.
int tagForTheButton = 0;
int yPossition = 0;
int xPossition = 0;
for (int numberOfTheColomn = 0; numberOfTheColomn < 6; numberOfTheColomn++) {
button = ;
button.adjustsImageWhenHighlighted = NO;
button.frame = CGRectMake(xPossition, yPossition, 64, 64);
button.tag = tagForTheButton;
;
;
;
yPossition=yPossition+100;
tagForTheButton++;
}
}
-(void)buttonPressed:(id)sender{
//This is my attempt to disable the buttons
//previous mistake used 2578
for (int numberForIncrease; numberForIncrease<6; numberForIncrease++) {
if (button.tag == numberForIncrease) {
UIButton *btn = (UIButton*);
btn.enabled=NO;
;
}
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您一定是错误地禁用了它。 <a href="https://developer.apple.com/library/IOs/documentation/UIKit/Reference/UIControl_Class/Reference/Reference.html#//apple_ref/occ/instp/UIControl/enabled" rel="noreferrer noopener nofollow">docs</a> <code>UIButton.enabled</code> 状态:</p>
<blockquote>
<p>If the enabled state is NO, the control ignores touch events and
subclasses may draw differently.</p>
</blockquote>
<p>通过添加 <code>NSLog()</code> 调用检查是否正在调用 <code>DisableButton</code>,并完全取消 <code>DisableButton</code> 方法:</p >
<pre><code>dispatch_sync(dispatch_get_main_queue(), ^{
self.view.userInteractionEnabled = NO;
_btn_sync_outlet.enabled = NO;
_btn_sync_outlet.userInteractionEnabled = NO;
});
</code></pre>
<p>这可能对你有帮助:)</p></p>
<p style="font-size: 20px;">关于iOS 禁用以编程方式创建的按钮,直到功能完成,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/27818270/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/27818270/
</a>
</p>
页:
[1]