【问题标题】:How to dismiss a TableViewController within code called by a storyboard push segue?如何在故事板推送 segue 调用的代码中关闭 TableViewController?
【发布时间】:2012-06-18 11:04:40
【问题描述】:

我知道如何处理 Storyboard 中的 push segues 以及使用导航控制器创建的后退按钮。我有一个主 tableview 通过 Storyboard 中的 push segue 连接到一个子 tableview。可以很好地在表格之间切换。

我想添加在子表视图中向左滑动手势以返回主表视图的功能。

首先在 Storyboard 中使用滑动手势识别器进行了尝试,但这导致主 tableview 成为子 tableview 的新子。

然后我在代码中尝试:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

...但这似乎只适用于模态转场

我有:

- (void)viewDidLoad
{
   [super viewDidLoad];

   UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
   [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
   [self.tableView addGestureRecognizer:recognizer]; 
}

- (void)handleSwipe:(UISwipeGestureRecognizer *)gestureRecognizer
{
   // need code here to dismiss the child tableview
}

【问题讨论】:

    标签: xcode uitableview push swipe segue


    【解决方案1】:

    今天终于弄明白了,效果很好:

    - (void)handleSwipe:(UISwipeGestureRecognizer *)gestureRecognizer
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
    

    找到答案:

    iOS 开发者库 > UINavigationController 类参考 > popToViewController

    【讨论】:

      猜你喜欢
      • 2013-06-30
      • 2016-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-11
      • 2012-05-12
      相关资源
      最近更新 更多