<i id='KwV9H'><tr id='KwV9H'><dt id='KwV9H'><q id='KwV9H'><span id='KwV9H'><b id='KwV9H'><form id='KwV9H'><ins id='KwV9H'></ins><ul id='KwV9H'></ul><sub id='KwV9H'></sub></form><legend id='KwV9H'></legend><bdo id='KwV9H'><pre id='KwV9H'><center id='KwV9H'></center></pre></bdo></b><th id='KwV9H'></th></span></q></dt></tr></i><div id='KwV9H'><tfoot id='KwV9H'></tfoot><dl id='KwV9H'><fieldset id='KwV9H'></fieldset></dl></div>

    <bdo id='KwV9H'></bdo><ul id='KwV9H'></ul>

<small id='KwV9H'></small><noframes id='KwV9H'>

<legend id='KwV9H'><style id='KwV9H'><dir id='KwV9H'><q id='KwV9H'></q></dir></style></legend>
      1. <tfoot id='KwV9H'></tfoot>

        iphone navigationController : 在退出当前视图之前等待 uialertview 响应

        时间:2023-06-11
        <tfoot id='oigVn'></tfoot>
      2. <i id='oigVn'><tr id='oigVn'><dt id='oigVn'><q id='oigVn'><span id='oigVn'><b id='oigVn'><form id='oigVn'><ins id='oigVn'></ins><ul id='oigVn'></ul><sub id='oigVn'></sub></form><legend id='oigVn'></legend><bdo id='oigVn'><pre id='oigVn'><center id='oigVn'></center></pre></bdo></b><th id='oigVn'></th></span></q></dt></tr></i><div id='oigVn'><tfoot id='oigVn'></tfoot><dl id='oigVn'><fieldset id='oigVn'></fieldset></dl></div>

      3. <small id='oigVn'></small><noframes id='oigVn'>

            <tbody id='oigVn'></tbody>
          <legend id='oigVn'><style id='oigVn'><dir id='oigVn'><q id='oigVn'></q></dir></style></legend>

              <bdo id='oigVn'></bdo><ul id='oigVn'></ul>
                  本文介绍了iphone navigationController : 在退出当前视图之前等待 uialertview 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个带有导航控制器管理的后退按钮的视图,我想检查当用户单击后退按钮时文件是否已保存.如果文件已保存,则返回上一个视图,否则 uialertview 会询问您是否要保存文件.

                  I have a view with a back button managed with a navigation controller and I want to check if a file has been saved when the user click on the back button. If the file has been saved you go back in the previous view, else a uialertview ask you if you want to save the file or not.

                  所以我这样做了,但视图消失了,之后出现了警报视图.

                  So I did that but the view disapear and the alertview appear after.

                  -(void)viewWillDisappear:(BOOL)animated {
                  if(!self.fileSaved){
                      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Save the file?"  delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes",nil];
                      [alert show];
                      [alert release];
                  }
                  }
                  
                  - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
                  {
                  switch (buttonIndex) {
                      case 0:
                          NSLog(@"NO");
                          break;
                      case 1:
                          NSLog(@"yes");
                          break;
                      default:
                          break;
                  }
                  }
                  

                  推荐答案

                  调用viewWillDisappear的时候已经晚了.您应该更早地拦截后退按钮.我从未这样做过,但我的建议是在您的 viewDidAppear 方法中的 navigationBar 属性上设置委托:

                  When viewWillDisappear is called, it's already too late. You should intercept the back button earlier on. I have never done it, but my suggestion is to set the delegate on the navigationBar property in your viewDidAppear method:

                  // save the previous delegate (create an ivar for that)
                  prevNavigationBarDelegate = self.navigationController.navigationBar.delegate;
                  
                  self.navigationController.navigationBar.delegate = self;
                  

                  不要忘记在 viewWillDisappear 中重新设置它:

                  Don't forget to set it back in viewWillDisappear:

                  self.navigationController.navigationBar.delegate = prevNavigationBarDelegate;
                  

                  然后拦截 shouldPopItem 方法:

                  Then intercept the shouldPopItem method:

                  - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {
                       if(!self.fileSaved) {
                           UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Save the file?"  delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes",nil];
                           [alert show];
                           [alert release];
                  
                           return NO;
                       }
                  
                     if ([prevNavigationBarDelegate respondsToSelector:@selector(navigationBar:shouldPopItem:)]) 
                        return [prevNavigationBarDelegate navigationBar:navigationBar shouldPopItem:item];
                  
                     return YES; 
                  }
                  

                  并在对话框的 YES 处理程序中,手动弹出控制器:

                  And in the YES handler for the dialog, manually pop the controller:

                  [self.navigationController popViewController:YES];
                  

                  这篇关于iphone navigationController : 在退出当前视图之前等待 uialertview 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:iOS 7 uinavigationcontroller 如何检测滑动? 下一篇:将嵌套在容器视图控制器中的 UINavigationController 添加到 UITabBarController

                  相关文章

                  <tfoot id='G6li5'></tfoot>

                  <i id='G6li5'><tr id='G6li5'><dt id='G6li5'><q id='G6li5'><span id='G6li5'><b id='G6li5'><form id='G6li5'><ins id='G6li5'></ins><ul id='G6li5'></ul><sub id='G6li5'></sub></form><legend id='G6li5'></legend><bdo id='G6li5'><pre id='G6li5'><center id='G6li5'></center></pre></bdo></b><th id='G6li5'></th></span></q></dt></tr></i><div id='G6li5'><tfoot id='G6li5'></tfoot><dl id='G6li5'><fieldset id='G6li5'></fieldset></dl></div>

                      <legend id='G6li5'><style id='G6li5'><dir id='G6li5'><q id='G6li5'></q></dir></style></legend>

                      <small id='G6li5'></small><noframes id='G6li5'>

                        <bdo id='G6li5'></bdo><ul id='G6li5'></ul>