Objective-C: How to access methods in other classes

后端 未结 2 1296
北海茫月
北海茫月 2021-01-15 09:35

I have what I know is a simple question, but after many searches in books and on the Internet, I can\'t seem to come up with a solution. I have a standard iPhone project th

相关标签:
2条回答
  • 2021-01-15 10:13

    You should probably take a look at one of the many Objective C tutorials, but the direct answer to your question is that you have not allocated and initialised an instance of your object. The code should look like:

    utils = [[Utils alloc] init];
    [utils myMethod];
    
    0 讨论(0)
  • 2021-01-15 10:17

    You just need to create the actual object.

    Your implementation only defines a pointer to an Util object but it still points to nil.

    utils = [[Util alloc] init];
    

    An alternative is to create static methods by replacing - by + in the method prefix.

    [Util myMethod];
    
    0 讨论(0)
提交回复
热议问题