接上述案例找BUG:【iOS开发-51】案例学习:动画新写法、删除子视图、视图顺序、延迟方法、按钮多功能用法及icon图标和启动页设置
(1)BUG:答案满了就不能再点击option按钮,答案没满就能点。
在optionClick方法的if(full)中设置,即判断答案是否满了,如果满了,则:
if (full) {
//如果答案满了,不管是否正确,只要满了,下面的option按钮就不能被点击
for (UIButton *optionBtn in self.optionView.subviews) {
optionBtn.enabled=NO;
}
}只要点击答案按钮,答案必然没有满,所以做个相反操作:
-(void)answerClick:(UIButton *)answerBtn{
//如果答案满了,不管是否正确,只要满了,下面的option按钮就不能被点击
for (UIButton *optionBtn in self.optionView.subviews) {
optionBtn.enabled=YES;
}
}即用以下语句:
self.optionView.userInteractionEnabled=NO;
self.optionView.userInteractionEnabled=YES;
但是除了以上两处之外,还要设置一处。就是因为我们判断了只要答案满了,那么父控件就不能交互按钮不能点击,虽然通过点击答案就能恢复交互。但是特殊情况是:我们点击满了,然后直接跳转到“下一题”,此时父控件依然是被锁定不能交互的。所以需要在“跳转到下一题”的方法中,设置父控件能交互。即
- (IBAction)nextQuestion {
self.optionView.userInteractionEnabled=YES;
}-(void)addOptionBtn:(NSQuestion *)question{
self.optionView.userInteractionEnabled=YES;
}——以下语句的原理在于:如果我们正在回答的时最后一道题,那么答对之后,它会继续调用nextQuestion方法,这个时候我们就判断它是否是最后一道题,如果是,则弹框。
——这里的弹框,我们用不到代理,但是为了复习代理知识,把self(控制器)设置为它的代理。
- (IBAction)nextQuestion {
if (self.index==self.questions.count-1) {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"恭喜" message:@"闯关成功!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"好的", nil];
[alert show];
return;
}
}@interface ViewController ()<UIAlertViewDelegate>
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%d",buttonIndex);
}(4)延伸一下,另一种提示框。ActionSheet
——提示框的展示稍有区别,它的出现是“在哪个视图中出现”,还有其他出现方式。
- (IBAction)nextQuestion {
if (self.index==self.questions.count-1) {
UIActionSheet *sheet=[[UIActionSheet alloc]initWithTitle:@"恭喜通关!" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"其他", nil];
[sheet showInView:self.view];
return;
}
}
【iOS开发-56】案例BUG:按钮的enabled、控件的userInteractionEnabled以及两种提示框UIAlert和UIActionSheet
原文:http://blog.csdn.net/weisubao/article/details/40213373