1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Objective C call method in main

Discussion in 'Mac Programming' started by ncohen, Apr 13, 2009.

  1. macrumors newbie

    Hi everybody,
    In my main I create an object recorder and I call one of its method... in this method I would like to call a method of my main... is it possible? How can I do that?

  2. macrumors 68040


    When you say "call a method of my main", do you mean call a function that is defined in the same source file as your main function, or do you mean invoke main?

    It seems somewhat strange to me, but you can call main like any other function. If you need to pass arguments you should do so via argc and argv, allocating a char ** of the appropriate size, then a char * for each argument. Again, this seems unusual and i would try to figure out a different design if possible.

  3. macrumors newbie

    sorry it wasn't clear...
    my main is a class (it's my MainView for iphone). In this class I create an object and call a function of this object (recorder)! In this object I need to call a function which belongs to MainView.

    Hope it's clearer now :)
  4. macrumors 68040


    oh, this makes a bit more sense. In the constructor or a setter for the "recorder" you should accept an object * of the type of MainView, and declare an instance variable of this type. When you instantiate the "recorder" object in a method in your MainView object, you would pass the variable "self" as this argument. In the "recorder" class you would store the pointer to the MainView object, and when needed, you would pass a message to this object to invoke a method.

    It's somewhat circular and hard to follow, but hopefully that's clear enough to get you where you need to go.

  5. macrumors newbie


Share This Page