开发者

iPhone - Get controller which pushed me

开发者 https://www.devze.com 2022-12-28 09:59 出处:网络
When I pushed a controller, is there a way to get the controller which pushed it (wi开发者_C百科thout sending it)? Or the first one?

When I pushed a controller, is there a way to get the controller which pushed it (wi开发者_C百科thout sending it)? Or the first one?

Thanks


You can get all view controllers from navigationController.viewControllers property. And the controller which pushed the currently visible controller is [navigationController.viewControllers objectAtIndex:[navigationController.viewControllers count] - 2].


Swift version:

let numberOfElements: Int? = self.navigationController?.viewControllers.count
let vc: ViewController = self.navigationController?.viewControllers[numberOfElements! - 2] as ViewController
0

精彩评论

暂无评论...
验证码 换一张
取 消