0

的顶部的参考视图我在一些UIViewControlle,需要返回到前一个,我用这个代码:如何获得在NavigationController

NSLog(@"%@", [self.navigationController popViewControllerAnimated:YES]); 
// Here I need to reference to the view I am going go to to call some function before this view is being displayed 
NSLog(@"Done button pressed"); 

但(写在我需要获得对执行弹出功能后显示的视图的引用(上一个viewController。

回答

1

)您可以使用UINavigationController属性topViewController,该属性为您提供堆栈顶部的视图控制器 只需在弹出之前调用它,或者将其设置为下一个:)

您还可以访问viewControllers属性以获取导航控制器堆栈包含的所有视图控制器。

+0

两者的回报'(空)'如果叫'popViewController前后获得参考对象'功能! –

+0

如果您在调用poViewController _method_之前调用它,该怎么办? – Geoffroy

+0

它返回当前视图控制器,但我需要一个ref到前面的viewController –

0

查看online docs中的viewControllers物业。它会给你视图控制器的一个阵列中的导航堆栈:

根视图控制器是在索引0处的阵列中,所述后视图控制器是在索引n-2,并且顶控制器是在索引n-1,其中n是数组中的项目数。

所以你想要的视图控制器将在索引n-2

0

再说什么@Geoffroy和@Maurice凯利说..

我应该调用popViewControllerAnimated:功能

// I should get reference to the object here before calling the popViewControllerAnimated: function 
    NSLog(@"%@", [self.navigationController popViewControllerAnimated:YES]); 
    NSLog(@"Done button pressed"); 
+0

'[self.navigationController popViewControllerAnimated:YES]'返回一个你刚才丢弃的视图控制器的引用。这不是你在原始问题中所要求的:*“执行弹出功能后显示的视图”* –