2013-07-08 24 views
0

我需要经过几个控制段,确保在进入下一个视图前点击了所有项。什么方式来检查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;,因为它被注释掉它种工作,除非在循环的最后一个项目被填满。或者,也许有更好的方法来检查我不知道的集合中的所有值。

回答

0

设置didPass = YES在您的方法的开始处(for循环之前)。

然后迭代您的outletCollection。只要你找到一个未点击的元素集didPass为NO。

+0

嗯,似乎工作,我本可以发誓,我试过了,感谢简单的答案! :) – BluGeni

1

我知道这个问题已经回答了,但这里是一个更清洁的方式来达到同样的:

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

谢谢你,我觉得必须有更好的方法! +1 – BluGeni

相关问题