Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

benkenobi

macrumors member
Original poster
May 27, 2009
33
0
Hey, I need help!

I've found places online asking the same question and none of the books I bought cover this.

I have a class I made called someclass.m, someclass.h, and I am in anotherclass.m . All I'm trying to do is call method1 from someclass.m


So I try doing this:
Code:
someclass *makeClass;
makeClass = [someclass alloc];
[makeclass method1];
It doesn't work...

So I try making an IBOutlet connecting the two classes together. Then I try calling the method [madeclass method1] Still does not work. Hope someone can help me before I shoot myself. thanks.
 
Code:
[[someclass alloc] init]
try that one, you always need init with alloc. also, you should really write your class names with an uppercase first character, that seperates them from variables and methods and makes it a lot easier to read!
 
I tried the alloc and everything else all i get is 'classname' undeclared.

I have looked through Apples documentation but honestly it is hard to understand (I'm not familiar with the language) thats why I bought the books that are easier. If the question was so fundamentally basic I would have figured it out by now. I've done this in Java and Visual basic. Objective C seems to be a little different. I find it odd why such a simple question can't be answered whenever I look... :apple:
 
I tried the alloc and everything else all i get is 'classname' undeclared.

I have looked through Apples documentation but honestly it is hard to understand (I'm not familiar with the language) thats why I bought the books that are easier. If the question was so fundamentally basic I would have figured it out by now. I've done this in Java and Visual basic. Objective C seems to be a little different. I find it odd why such a simple question can't be answered whenever I look... :apple:

it IS very simple. the code I posted above works perfectly, but of course you must make objective C aware of your custom class by importing the .h file of the class at the top of your file via #import
 
It would be awesome if this ever worked.
sn3.jpg
 
It's working now. You had to put -(void) methodname, in the header. The Apple documentation is useless. thanks
 
It's working now. You had to put -(void) methodname, in the header. The Apple documentation is useless. thanks

the apple documentation is far from useless ^^ and yes, you have to put all your methods in your header, otherwise it will not be recognized. every objective c tutorial would have told you that ;-)
 
It's working now. You had to put -(void) methodname, in the header. The Apple documentation is useless. thanks

Actually its not useless at all. Your problem here is that you've failed to understand the basics of Objective-C - that is, you need to declare your methods in header files. You're naming conventions are also completely out of whack - classes should be CamelCased - the fact you've missed this seems to indicate you've not read the documentation or the beginner's guide to Objective-C very thoroughly and I'd suggest starting it again from the beginning.
 
that is, you need to declare your methods in header files. You're naming conventions are also completely out of whack - classes should be CamelCased - the fact you've missed this seems to indicate you've not read the documentation or the beginner's guide to Objective-C very thoroughly

Yea.. I've barely read more than 3 lines of it. I'm sure its not useless, but reading through the tutorial books are easier for me and a lot less boring... Unfortunately, it did not mention anything about CamelCasing or saying you HAD to declare methods in the header. I wonder why they didn't make it show up as an error like it would do with an action method.
 
It shows up as a warning because it will still compile and if the object responds to that message it will work; but because it's not declared in the header the compiler can't be sure at compile-time that it responds to that message, hence the warning.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.