Ios “自定义”上的“后退”按钮标题;替换“;塞格

Ios “自定义”上的“后退”按钮标题;替换“;塞格,ios,uiviewcontroller,uinavigationcontroller,segue,uinavigationitem,Ios,Uiviewcontroller,Uinavigationcontroller,Segue,Uinavigationitem,我有一个自定义的“替换”序列,用另一个替换当前的viewcontroller。这很有效。但是,“后退”按钮标题始终变为“后退”。segue的工作原理如下: 视图控制器A->视图控制器B 然后,ViewController B对ViewController C执行替换序列。然后堆栈为: ViewController A->ViewController C 这是ReplaceSegue.swift的代码: public class ReplaceSegue: UIStoryboardSegue {

我有一个自定义的“替换”序列,用另一个替换当前的viewcontroller。这很有效。但是,“后退”按钮标题始终变为“后退”。segue的工作原理如下:

视图控制器A->视图控制器B

然后,ViewController B对ViewController C执行替换序列。然后堆栈为:

ViewController A->ViewController C

这是ReplaceSegue.swift的代码:

public class ReplaceSegue: UIStoryboardSegue
{
    public var animated = true

    public override func perform()
    {
        let navigationController: UINavigationController = sourceViewController.navigationController!

        var controllerStack = navigationController.viewControllers
        let index = controllerStack.indexOf(sourceViewController)
        controllerStack[index!] = destinationViewController

        navigationController.setViewControllers(controllerStack, animated: animated)
    }
}
对于我的ViewController:

func replaceAgendaViewController()
{
    let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let agendaViewController = mainStoryboard.instantiateViewControllerWithIdentifier("AgendaViewController") as! AgendaViewController
    let segue = ReplaceSegue(identifier: replaceSegueId, source: self, destination: agendaViewController) { () -> Void in

    }
    segue.animated = false
    segue.perform()
}
我已经尝试过这段代码,但我理解为什么它不起作用,因为它在被替换的ViewController上设置了navigationItem:

navigationItem.backBarButtonItem = UIBarButtonItem(title: " ", style: UIBarButtonItemStyle.Plain, target: nil, action: nil) 

我也不想在执行segue之前设置back按钮标题,因为ViewController包含可能不需要该back按钮标题的其他segue。有什么建议吗?

很容易修复,我只是将代码添加到ViewController A:

public override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
    switch (segue.identifier!) {
    case agendaSegueId:
        navigationItem.backBarButtonItem = UIBarButtonItem(title: " ", style: UIBarButtonItemStyle.Plain, target: nil, action: nil) 
        ...
    }
}