IPhone: save with confirmation during reverse navigation

In my iPhone application, I have a navigation controller, a home screen and some editing screens. On the editing screen, the user makes an input, which must be verified before I can save it. Ideally, I would like to automatically update the data for reverse navigation without the additional “Done” button. Can I do some checking and save on the reverse navigation (that is, when the user clicks on the standard "Back" button) so that I can stop navigation and show an error message if something is wrong?

I see several other possibilities:

  • Create your custom left button and make it look like the standard one. (Why didn't Apple include this button style in the open API?)
  • Add the "Finish" button and save the data only if the user deletes it.

but I like both of these choices much less. Therefore, if there is a way to achieve what I want, I would like to use it.

+3
source share
6 answers

Basically you want to override the action from backBarButtonyour root view controller and do your check. If the check has passed, call UINavigationController popViewControllerAnimated:, otherwise an error warning or something else will appear.

, target action navigationItem.backBarButton, . -, .

, . UIBarButtonItem, "", . , , . .

+3

[popViewControllerAnimated:] UIViewController. , , .

0

, , ", " ", - viewWillDisappear :

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if (!isPushing) {
        // Apply your changes here
    }
}

isPushing , , True , ( ...), viewWillDisappear , "".

:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Example of pushing a new controller onto the navigation stack yourself...
    isPushing = YES;    // You have to set that boolean here...
    [self.navigationController pushViewController:myNewController animated:YES];
}
0

, , , UITableView, , .

0

, .

, (, ) (, " " ). , , :

self.navigatingTo = NavigatingToNameEdit;

viewWillAppear :

if (self.navigatingTo == NavigatingToNameEdit) {
    self.name = self.nameEditView.name;
    // Don't forget to reset navigatingTo:
    self.navigatingTo = NavigatingToNone;
}
0

, , , . , Apple , . ( , ), AlertViews "clickedButtonAtIndex", . , . 2 ...

0

Source: https://habr.com/ru/post/1725730/


All Articles