我正在开发一个涉及用户填写文本字段和浏览视图的 iOS 应用程序。目前,导航有时使用导航栏处理,有时通过按钮处理。我尝试将一些字段设为必填:如果这些字段留空,则阻止通过应用程序的进度。这适用于基于按钮的导航,但不适用于导航栏。我的代码如下:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"birthPopBus"]) {
currentPopoverSegue = (UIStoryboardPopoverSegue *)segue;
pvc = [segue destinationViewController];
[pvc setDelegate:self];
}
else if([[segue identifier] isEqualToString:@"SecondBusPageSegue"]) {
//This code breaks the next page
//Check fields, and create error message (code removed for readability)...
//If the fields are not filled in, display the alert with generated string.
if(!(first && last && email && phone && address && zip && ssn && birthFilled)){
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Required Fields Missing:"
message:alertMessageMutable
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
}
//Perform the segue, should only run if all required fields are filled.
else{
[self fillBus1Dictionary];
NSLog(@"application dictionary: %@", self.application);
SecBusPage * secondBusPage = segue.destinationViewController;
secondBusPage.application = self.application;
}
}
}
错误消息将显示,但仅在视图更改之后。因此,用户进入 SecondBusPage,并收到一条提示“您没有填写 X、Y、Z 字段”的警报。这对他们来说非常令人困惑。防止导航栏切换视图的任何想法?
提前致谢!