Calling a method from another class

Discussion in 'iOS Programming' started by Grey0815, Feb 15, 2010.

  1. Grey0815 macrumors newbie

    Feb 15, 2010
    Hi there.

    I’m rather new to Objective-C and objective oriented programming. I’ve tried to teach myself through books, but I seem to miss a basic concept here.

    I think my problem is best explained through an example.

    I’m trying to create a UINavigationController based application with some subviews. I want to use the toolbar, that’s provided with the UINavigationController, but I do not want it to show on all subviews. Just some of them.

    Is start with the basic class “testAppDelegate.m/.h”, create an instance of the UINavigationController class with UINavigationController = *navigationController in that class. Now I add views and a navigationBar and everything works fine.

    The toolbar isn’t showing yet, as it is hidden by default. If I change that via navigationController.toolbarHidden = NO then I see the toolbar, but I see it all the time.

    So I create a subclass of UIViewController named myViewController. There I use the viewWillAppear Method to show the toolbar, when the view is pushed. But how do I do that. myViewController cannot access the navigationController created in testAppDelegate.

    Any help for a newb?

    My first instinct was to create a method in testAppDelegate that sets navigationController.toolbarHidden = NO. That works fine, but only if I call the method from within the class (via “self”). If I call the method from myViewController, the App crashes.
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    The "Using View Controllers With Other View Controllers" section in the class reference for UIViewController might be able to get you started, especially the second paragraph.

Share This Page