【问题标题】:How can to go back to previous view programmatically without UINavigationController?如果没有 UINavigationController,如何以编程方式返回上一个视图?
【发布时间】:2014-07-07 07:25:26
【问题描述】:

如果没有UINavigationController,如何以编程方式返回上一个视图,因为我发现的所有示例都使用UINavigationController

我正在制作用于发送反馈的视图,我希望在更多应用中使用此视图。
如果我使用 UINavigationController 比应用程序需要有UINavigationController 使用我的视图发送反馈。

这可能吗?如何做?

这是我如何显示发送反馈视图的代码:

- (IBAction)showFeedbackView:(id)sender {

    WOC_FeedbackViewController *feedbackView = [[WOC_FeedbackViewController alloc] init];

    [self presentViewController:feedbackView animated:YES completion:nil];
}

【问题讨论】:

标签: ios uiviewcontroller


【解决方案1】:

用这个返回

[self dismissViewControllerAnimated:YES completion:nil];

【讨论】:

    【解决方案2】:

    根据您的项目工作(故事板或 XIB),您可以使用 presentViewController。但那是当您保留对最后一个 viewController 标识符的引用时。

    如果你知道你的 viewController NSString *yourID; 的 ID;

    1) 初始化你的 viewController

    故事板

    UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:yourID];
    

    对于 XIB

    UIViewController *vc = [UIViewController alloc]initWithNibName:yourID bundle:nil];
    

    2) 展示你的 ViewController

    [self presentViewController:vc animated:YES completion:nil];
    

    P.S 这是一种方法,但您应该使用navigationController,因为您可以在堆栈上保留viewController 的内存,因此当您需要再次访问它时,您可以更快地访问它。换句话说,UINavigationController 应用于您在 App Store 上看到的每个 iOS 应用程序。

    【讨论】:

      【解决方案3】:

      Swift 中,您可以使用以下代码行返回到上一个视图控制器无需导航控制器

      self.dismissViewControllerAnimated(true, completion: nil)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-11-30
        • 2011-04-08
        • 2015-03-14
        • 2016-06-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多