So I have this custom class with just a test method that does nslog. I am going to reuse this method many times in my app. The interface looks like this.
@interface TestViewController: UIViewController { CMImageMover * imageMover }
Then in the view did load I:
imageMover = [[CmImageMover alloc] init];
If I do:
[imageMover testMethod];
Right after the alloc and init it works in the viewDidLoad function but if I call it again from another function in the view controller nothing works and the class method does not get called.
What am I doing wrong here. Every other var I declare like NSArray/NSTimer, I do the say way and I am able to access and use it throughout my controller.
When you say “if I call it again from another function in the view controller nothing works” then first thing to check is what you are sending the
testMethod. It could be nil, in which case nothing will happen. In objective C sending a message to nil does nothing. Add an NSLog to find out, e.g.If the NSLog shows it is nil – or something crazy – then follow up what you are doing with the imageMover ivar.
You mention a class method in your question, but don’t refer to it in your code snippets.
If you have defined
testMethodas a class method it will, of course, fail if you send that message to an instance. (And it will fail noisily.) A class method would be introduced like this:An instance method would be introduced like this:
Apologies if this is all screamingly obvious to you and missing the point of the question. It’s not that clear from your question where the issue lies.