开发者社区> 问答> 正文

关于检测outletcollection中所有项目 的问题

在进入下一个视图中需要确保当前的控制段都被选中了

-(void)checkAllSegments
{   BOOL alertShown;
    alertShown = NO;
    for (UISegmentedControl *swItem in allSegmentControlOutlet) {
        int selectedSegment = swItem.selectedSegmentIndex;
        swItem.segmentedControlStyle = UISegmentedControlStyleBar;
//didPass = YES;
        if (selectedSegment == -1) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Fill in all forms"
                                                            message:@"Please go back and fill in missing info"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"                                                  otherButtonTitles:nil];

           // [swItem setTintColor:[UIColor redColor]];
            if (!alertShown) {
                [alert show];
                alertShown = YES;
                didPass = NO;
                return;
            }
        }
    }
    if (didPass) {
        [self performSegueWithIdentifier:@"ToHiring" sender:self];
        }
}

但是我不知道应该将 didPass = YES;放到哪,这句代码所在的位置会被注释掉。除非最后一条循环完成。有没有更好的方法解决?

展开
收起
爵霸 2016-03-19 09:16:17 1559 0
1 条回答
写回答
取消 提交回答
  • 给你改一下。

     -(void)checkAllSegments
        {   BOOL alertShown;
            alertShown = NO;
            for (UISegmentedControl *swItem in allSegmentControlOutlet) {
                int selectedSegment = swItem.selectedSegmentIndex;
                swItem.segmentedControlStyle = UISegmentedControlStyleBar;
        //didPass = YES;
                if (selectedSegment == -1) {
                    alertShown=YES;
                    break;  /////如果有一个没有被选择,直接退出for循环
                }
            }
            if (alertShown) {
                  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Fill in all forms"
                                             message:@"Please go back and fill in missing info"
                                             delegate:nil
                                             cancelButtonTitle:@"OK"
                                             otherButtonTitles:nil];
            }else {
               [self performSegueWithIdentifier:@"ToHiring" sender:self];
            }
    
        }
    2019-07-17 19:07:12
    赞同 展开评论 打赏
问答分类:
Go
问答地址:
相关产品:
问答排行榜
最热
最新

相关电子书

更多
内容安全检测与管控 立即下载
阿里巴巴代码缺陷检测探索与实践 立即下载
复杂环境下的视觉同时定位与地图构建 立即下载