Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 检查outletcollection中所有项的值的方法是什么_Iphone_Ios - Fatal编程技术网

Iphone 检查outletcollection中所有项的值的方法是什么

Iphone 检查outletcollection中所有项的值的方法是什么,iphone,ios,Iphone,Ios,在转到下一个视图之前,我需要浏览几个受控的部分,确保所有部分都已单击 到目前为止,我有: -(void)checkAllSegments { BOOL alertShown; alertShown = NO; for (UISegmentedControl *swItem in allSegmentControlOutlet) { int selectedSegment = swItem.selectedSegmentIndex; swItem

在转到下一个视图之前,我需要浏览几个受控的部分,确保所有部分都已单击

到目前为止,我有:

-(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
因为在注释掉它的地方,除非循环中的最后一项被填充,否则它会起作用。或者可能有更好的方法来检查我不知道的集合中的所有值。

在方法的开头(for循环之前)设置
didPass=YES


然后在outletCollection上迭代。一旦您找到一个未勾选的元素集,它就会被设置为NO.

我知道这个问题已经得到了回答,但这里有一个更简洁的方法来实现同样的效果:

// Check all controls and get the minimum selectedIndex
NSNumber *minIndex = [yourCollection valueForKeyPath:@"@min.selectedSegmentIndex"];
if ([minIndex isEqual:@(UISegmentedControlNoSegment)]) {
    // At least one control is unselected
}

嗯,这似乎管用,我发誓我试过了,谢谢你简单的回答!:)谢谢你,我想一定有更好的办法+1.