uinavigationbar - Cancel Navigation Bar action in iOS -
i'm working on ios application involves users filling out text fields , navigating through views. currently, navigation handled using navigation bar, , through buttons. tried make of fields required: preventing progress through application if fields left blank. worked button based navigation not navigation bar. code follows:
- (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 next page //check fields, , create error message (code removed readability)... //if fields not filled in, display alert 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 segue, should run if required fields filled. else{ [self fillbus1dictionary]; nslog(@"application dictionary: %@", self.application); secbuspage * secondbuspage = segue.destinationviewcontroller; secondbuspage.application = self.application; } } }
the error message show up, after view has changed. user gets secondbuspage, , gets alert saying "you didn't fill out fields x, y, z." confusing them. ideas preventing navigation bar switching views?
thanks in advance!
you can achieve implementing conditional segues 1 in answer in below linked post
conditional segue using storyboard
you cannot cancel segue prepareforsegue. instead of perform segues based on condtions
Comments
Post a Comment