我正在开发一个 iOS 应用程序,该应用程序涉及用户填写文本字段和浏览 View 。目前,导航有时使用导航栏,有时通过按钮来处理。我尝试将某些字段设为必填:如果这些字段留空,则会阻止应用程序的进展。这适用于基于按钮的导航,但不适用于导航栏。我的代码如下:
- (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;
}
}
}
错误消息将会显示,但仅在 View 更改后才会显示。因此,用户进入 SecondBusPage,并收到一条警告,提示“您没有填写字段 X、Y、Z”。这对他们来说非常困惑。有什么办法可以防止导航栏切换 View 吗?
提前致谢!
最佳答案
您可以通过实现条件转场轻松实现这一目标,就像我在下面链接的帖子中的回答中的那样
Conditional Segue Using Storyboard
您无法从prepareForSegue 取消segue。相反,根据条件执行 Segues
关于ios - 取消 iOS 中的导航栏操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18986832/