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.