View Full Version : Objective C call method in main
Apr 13, 2009, 02:00 PM
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?
Apr 13, 2009, 02:30 PM
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.
Apr 13, 2009, 02:37 PM
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 :)
Apr 13, 2009, 02:39 PM
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.
Apr 13, 2009, 02:52 PM