使用UIBarButtonItem展开Segue

时间:2014-09-11 15:09:31

标签: ios objective-c segue uistoryboard uibarbuttonitem

我已根据此question

的答案成功实施了展开segue

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

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

我之前使用了BarButton项来触发推送segue,所以我不确定为什么我也不能使用它触发一个unwind segue。有人有什么建议吗?

1 个答案:

答案 0 :(得分:1)

在IB中,您需要从VC2向下拖动到VC2底部的绿色“退出”图标,然后从与VC1对应的列表中选择展开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
    }
}