views:

478

answers:

2

Hi guys I know this is a pretty well posted thing to do, but I still can't work it out.

I have an instance method saveAllDataJobs in Jobs.m.

- (void) saveAllDataJobs { ... }

I am in DetailViewController.m and I want to run the method saveAllDataJobs, which is in Jobs.m. What precisely do I need in order for this code to run.

Sorry for the repeat question, but I can't work it out.

Regards

A: 

Call the method with [someJobsInstance saveAllDataJobs] ?

Is that is not an answer to your question then you need to explain more what you are trying to accomplish. I get the feeling that this is more about application architecture than about calling methods.

St3fan
can you explain the someJobsInstance bit. That is what I am having trouble with.OTherwise I can post more elaborate code.
norskben
Paste more code.
St3fan
+1  A: 

Read about "delegation" in documents. Here is the basics:

When you create DetailViewController, you give it an ivar:

@interface DetailViewController {
    id delegate;
}

@property (assign) delegate;
@end

@implementation DetailViewController

@synthesize delegate;

@end

Then:

DetailViewController *controller = [[DetailViewController alloc] initWithNibName...]
controller.delegate = jobs; // "jobs" is of class Jobs, instantiated somewhere else

Later, when you need to call some method on jobs inside detailViewController, you do

if ([self.delegate respondsToSelector:@selector(saveAllDataJobs)]) {
    [self.delegate saveAllDataJobs];
}

There are more details around this, but this is the basic pattern.

Jaanus
thats going to take some deciphering. thanks for your help this far, now i need to try and figure it out.
norskben
The basic idea is this: whoever creates the "controller" object also gives it reference to "jobs" object, so "controller" knows how to call methods on "jobs".
Jaanus