yue1liang1chuan 于 2013.07.09 13:43 提问
- 检测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;
放到哪,这句代码所在的位置会被注释掉。除非最后一条循环完成。有没有更好的方法解决?
-
-
zhanglei5415
2013.07.09 14: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];
}
}
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!