【问题标题】:Unwind Segue with UIBarButtonItem使用 UIBarButtonItem 展开 Segue
【发布时间】:2014-09-11 15:09:30
【问题描述】:

我已经根据question 的答案成功实现了一个 unwind segue

我无法使用 BarButton Item 来触发展开,而不是使用 Button。 Button 项正确触发了 segue,但是当我将 BarButton 项连接到下面的方法时,根本没有发生转换。

- (IBAction)unwindSegue: (UIStoryboardSegue *)segue 
{
    // Do Something    
}

我之前使用过 BarButton 项目来触发推送转场,所以我不确定为什么我不能也使用它来触发展开转场。有人有什么建议吗?

【问题讨论】:

    标签: ios objective-c segue uistoryboard uibarbuttonitem


    【解决方案1】:

    在 IB 中,您需要从 VC2 向下拖动到 VC2 底部的绿色 Exit 图标,然后从对应于 VC1 的列表中选择 unwind segue。这会将 VC2 连接到 VC1 中的展开。要“触发”它,您可以执行以下操作:

    VC2

    - (IBAction)buttonAction:(id)sender
    {
        UIBarButtonItem *barButton = (UIBarButtonItem *)sender;
    
        // use a conditional like this if you want to use this action method for multiple buttons
        // Otherwise, just call performSegueWithIdentifier
        if (barButton == self.navigationItem.leftBarButtonItem) {
            [self performSegueWithIdentifier:@"myStoryboardIdForVC1" sender:self];
        }
    }
    

    VC1

    - (IBAction)unwindToVC1:(UIStoryboardSegue *)segue
    {
        // use condidtionals like this if you want to use the unwind from multiple sources
        if ([segue.identifier isEqualToString:@"mySegueIdfromVC2"]) {
           // do something
        }
        if ([segue.identifier isEqualToString:@"mySegueIdfromVC3"]) {
           // do something
        }
        if ([segue.identifier isEqualToString:@"mySegueIdfromVC4"]) {
           // do something
        }
    }
    

    【讨论】:

    • 感谢您的帮助!我确实确保了 VC2 的 UIBarButtonItem 连接到 VC1 的 unwind segue。我只是尝试将 UIBarButtonItem 连接到如下所示的操作:- (IBAction)goBack:(id)sender { [self.navigationController popViewControllerAnimated:YES]; } 但是当 UIBarButtonItem 时,VC2 仍然没有展开到 VC1。我错过了什么明显的东西吗?
    • 我还有一些想法,我们在这里聊聊:chat.stackoverflow.com/rooms/61079/unwind-seguea
    • 显然我需要 20 声望才能在聊天室中聊天(我只有 18 :/)
    • 我尝试添加将 IBAction 更改为 [self dismissViewControllerAnimated:YES completion:Nil];,但这似乎也不起作用。
    • 将 ViewController 直接连接到 Exit (unwind segue)。当你关闭它应该放松
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 2015-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多