0

我想在 segue 后退一步时执行一些代码。For example, when the back button gets selected, I want to perform some code.

我无法从后退按钮创建新的展开动作,因为情节提要中没有后退按钮。有没有办法在选择后退按钮后插入代码?

4

1 回答 1

0

如果你想坚持使用默认的后退按钮,一种方法是继承导航控制器,并覆盖 popViewControllerAnimated: 当你点击后退按钮时调用它。

-(UIViewController *)popViewControllerAnimated:(BOOL)animated {
    UIViewController *vcToBePopped =[super popViewControllerAnimated:animated];
    id vc = self.viewControllers.lastObject; // this will be the controller you're going back to
    if ([vc isKindOfClass:IntendedViewController class]) { // replace IntendedViewController with the actual class name you care about
        [(IntendedViewController *)vc someMethod];
    }

    return vcToBePopped;
}
于 2015-02-16T02:29:53.350 回答