Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing Method from other Classes Objective-C
    primarykey
    data
    text
    <p>Looked for an answer for this question, but I haven't found a suitable one yet. I'm hoping you guys (and gals) can help me out! (This is for an iPhone app)</p> <p>Alright, I have a Mutliview application. Each view has it's own class, and everything is happy. However, the different classes sometimes call the same method. Up until now, I have simply wrote that Method twice, in both of the class files.</p> <p>This is what I want to do though:</p> <p>I want to make a new class, in It's own file, that has all the "Common" Methods. Then, whenever another class needs to call the Method, I simply call it from the other file. This way, when I want to change the Method, I only need to change it in one place, and not all the places...</p> <p>I'm not sure how I'd do this, which is why I'm asking for help. I'm a little rusty and new for Objective-C, so pretty examples will help me a lot. Allow me to give you one.</p> <p>File: ViewController1.m</p> <pre><code>@implementation ViewController1 //Do Some awesome stuff.... CALL "CommonMethod" HERE @end </code></pre> <p>File: ViewController2.m</p> <pre><code>@implementation ViewController2 //Do Some awesome stuff.... CALL "CommonMethod" HERE @end </code></pre> <p>File: CommonClass</p> <pre><code>@implementation commonClass - (void)CommonMethod:(id)sender { //So some awesome generic stuff... } @end </code></pre> <p>I feel like I need to #import the other file, make an Object from the class and call the Method from the Object... How do I do that?</p> <p>Thanks again!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload