Objective-c (iphone sdk) accessor instance method from separate class

I know this is a pretty well written thing, but I still can't seem to solve it.

I have an instance method saveAllDataJobs in Jobs.m.

- (void) saveAllDataJobs { ... }

      

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

Sorry for the duplicate question, but I can't seem to process it.

Hello

0


a source to share


2 answers


Read about delegation in the docs. Here's 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 any method to work inside detailViewController, you do

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

      

There are more details on this, but this is the basic template.

+1


a source


Call the method with [someJobsInstance saveAllDataJobs]

?



Isn't that the answer to your question, then you need to explain more of what you are trying to achieve. I feel like this is more about application architecture than calling methods.

0


a source







All Articles