How to find topmost view controller on iOS

后端 未结 30 2873
遥遥无期
遥遥无期 2020-11-22 08:40

I\'ve run into a couple of cases now where it would be convenient to be able to find the \"topmost\" view controller (the one responsible for the current view), but haven\'t

30条回答
  •  臣服心动
    2020-11-22 08:54

    I recently got this situation in one my project, which required to displayed a notification view whatever the controller displayed was and whatever was the type (UINavigationController, classic controller or custom view controller), when network status changed.

    So I juste released my code, which is quite easy and actually based on a protocol so that it is flexible with every type of container controller. It seems to be related with the last answers, but in a much flexible way.

    You can grab the code here : PPTopMostController

    And got the top most controller using

    UIViewController *c = [UIViewController topMostController];
    

提交回复
热议问题