yue1liang1chuan 2013-07-09 05:43 采纳率: 0%
浏览 1923
已采纳

检测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;放到哪,这句代码所在的位置会被注释掉。除非最后一条循环完成。有没有更好的方法解决?

  • 写回答

1条回答 默认 最新

  • ReyZhang 移动开发领域新星创作者 2013-07-09 06:03
    关注

    给你改一下。

     -(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];
            }
    
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64