How to get the current view controller in iPhone application

  • Hi
    Can I get the class type of the current view controller running in the
    application, I have Tab Controller and Navigation Controller in my
    application, at some time I need to get the current view controller using
    code, can any body please tell me a method or code segment to do this.
    isKindOfClass: can be used to test the class type. But how can I get the
    current active view contrller? please help me to solve this.
    Thank you,
    Tharindu
  • Well, if you're using a TabBarController and a Navigation Controller,
    then theoretically you're having to use a ViewController to controller
    whatever is on the screen.  That means that in almost all
    circumstances (the exception being threaded code), the current view
    controller would be.... self.

    If for some strange reason that doesn't work for you, then you can
    register an object (like an app controller or something) to receive
    notifications whenever a tab bar or navigation controller changes
    views, then just store a pointer to whatever the topViewController or
    selectedViewController is.

    Dave

    On 6 Jan, 2009, at 9:20 PM, Tharindu Madushanka wrote:

    > Hi
    > Can I get the class type of the current view controller running in the
    > application, I have Tab Controller and Navigation Controller in my
    > application, at some time I need to get the current view controller
    > using
    > code, can any body please tell me a method or code segment to do this.
    > isKindOfClass: can be used to test the class type. But how can I get
    > the
    > current active view contrller? please help me to solve this.
    > Thank you,
    > Tharindu