以编程方式同时关闭

以编程方式同时关闭

本文介绍了以编程方式同时关闭 UINavigation 视图和 Modal 视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在这个网站上尝试了一些答案,但似乎都与我的问题无关

I have tried a few answers on this site, but none of them seem to relate to my problem

我有一个 MasterDetail 应用程序,它有两种我正在使用的 segues.当您按下详细视图上的按钮时,它会使用 push segue 并将另一个详细视图推送到该按钮上.在新的 detailview(刚刚被按下的那个)中有一个按钮,它使用模态 segue 调用另一个 UIView(表单).

I have a MasterDetail app which has a two types of segues that I am using. When you press a button on the detail view, it uses a push segue and pushes another detail view onto that. In the new detailview (the one that was just pushed on) there is a button which calls up another UIView (form sheet) using a modal segue.

我想做的是当用户选择一行时,UIAlertView 会同时显示一条消息(不必在同时时间)它会解除 UIViewcontroller(模态)并从被推送的 Viewcontroller 返回.基本上,我需要能够关闭所有视图控制器、一个模式和一个推送(导航),以便视图返回到它们开始时的原始主屏幕.

What I am trying to do is when the user selects a row, a UIAlertView will show up displaying a message, while at the same time (doesn't have to be at the same time) it dismisses the UIViewcontroller (modal) and goes back from the Viewcontroller that was pushed on. Basically, I need to be able to dismiss all viewcontrollers, one modal and one push (nav) so that the view returns to the original main screen that they started with.

我的 UIAlertView 工作正常,我可以使用 [self.dismissViewControllerAnimated:YES completion:nil]; 让模态视图控制器关闭,但我不知道如何关闭下一个 Viewcontroller(在导航控制器中).使用这个:[self.navigationController popToRootViewControllerAnimated:NO]; 不起作用.

I have the UIAlertView working fine and I can get the modal viewcontroller to dismiss by using [self.dismissViewControllerAnimated:YES completion:nil]; but I don't know how to dismiss the next Viewcontroller (which is in a navigation controller). Using this: [self.navigationController popToRootViewControllerAnimated:NO]; does not work.

这里是我要调用函数来删除所有视图的地方:

Here is where I want to call the function to remove all views:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlWithIDAndChallenge];

    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

    UIAlertView *message = [[UIAlertView alloc] initWithTitle@"Started" message:@"The challenge has begun!" delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil];

    [message show]

    //right here is where I would normally dismiss the modal VC
    //here is where I would like to dismiss all VC

}

推荐答案

如果需要,在 iOS 6.0(及更高版本)项目中,您可以使用 unwind segue.例如,您可以:

If you want, in iOS 6.0 (and later) projects you can use an unwind segue. For example, you can:

  1. 在您的顶级视图控制器(您想要展开的控制器,而不是您要展开的控制器)中,编写一个展开segue 方法,在本例中称为 unwindToTopLevel (我个人认为,如果 segue 带有一些关于 segue 目的地的指示,则它很有用,原因在我们进入步骤 3 时将变得明显, 下面):

  1. In your top level view controller (the one you want to unwind to, not the controller you're going to unwind from), write an unwind segue method, in this case called unwindToTopLevel (personally, I find it useful if the segue bears some indication as to what the destination of the segue is, for reasons that will become apparent when we get to step 3, below):

- (IBAction)unwindToTopLevel:(UIStoryboardSegue *)segue
{
    NSLog(@"%s", __FUNCTION__);
}

  • 在您将启动展开的 Interface Builder 场景中, - 从视图控制器图标拖动到退出图标以创建展开转场:

  • In the Interface Builder scene from which you will initiate the unwind, -drag from the view controller icon to the exit icon to create the unwind segue:

    通常您会定义从按钮到出口出口的转场(您就完成了),但如果您想以编程方式调用转场,您可能希望在控制器和展开出口之间创建它,例如如上所示.

    Generally you'd define the segue from a button to the exit outlet (and you're done), but if you want to invoke the segue programmatically, you might want to create it between the controller and the unwind outlet, like shown above.

    您会看到一个小弹出窗口,其中包含您的展开转场的名称(来自呈现的控制器......就像魔术一样):

    You'll get a little pop up that includes the name of your unwind segues (from the presenting controllers ... it's like magic):

    如果您要以编程方式调用该转场,则必须在 IB 窗口左侧的文档大纲中选择该展开转场,完成此操作后,您可以提供展开转场故事板 ID:

    If you're going to invoke that segue programmatically, you have to select that unwind segue in the document outline on the left side of the IB window and once you've done that, you can give the unwind segue a storyboard id:

    我通常使用展开转场的名称作为情节提要 ID,但您可以使用任何您想要的名称.

    I generally use the name of the the unwind segue for the storyboard id, but you can use whatever you want.

    现在,完成此操作后,您的警报视图可以调用 segue:

    Now, having done that, your alert view can invoke the segue:

    - (IBAction)didTouchUpInsideButton:(id)sender
    {
        [[[UIAlertView alloc] initWithTitle:nil message:@"go home" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil] show];
    }
    
    #pragma mark - UIAlertViewDelegate
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        if (buttonIndex != [alertView cancelButtonIndex])
        {
            [self performSegueWithIdentifier:@"unwindToTopLevel" sender:self];
        }
    }
    

  • 这篇关于以编程方式同时关闭 UINavigation 视图和 Modal 视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    1403页,肝出来的..

    09-06 20:33