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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作