0

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

2
  • An instance of class Jobs. Then [jobs saveAllDataJobs]; Commented Jan 28, 2010 at 14:59
  • no, thats not right. Thats for a class method (the +), not the instance method (The -) one. I was looking for a litle more than one line. Commented Jan 28, 2010 at 15:05

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thats going to take some deciphering. thanks for your help this far, now i need to try and figure it out.
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".
0

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.

1 Comment

can you explain the someJobsInstance bit. That is what I am having trouble with. OTherwise I can post more elaborate code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.