Objective C call method in main

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

  1. macrumors newbie

    Joined:
    Mar 31, 2009
    #1
    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?

    Thanks
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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.

    -Lee
     
  3. thread starter macrumors newbie

    Joined:
    Mar 31, 2009
    #3
    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

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    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.

    -Lee
     
  5. thread starter macrumors newbie

    Joined:
    Mar 31, 2009
    #5
    thx!
     

Share This Page