当segue返回一步时,我想执行一些代码。例如,当选择后退按钮时,我想执行一些代码。
我无法从后退按钮创建新的展开动作,因为故事板中没有后退按钮。一旦选择了后退按钮,有没有办法插入代码?
答案 0 :(得分: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;
}