Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8381809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:46:47+00:00 2026-06-09T16:46:47+00:00

A very basic question on how to interact between classes here: how can I

  • 0

A very basic question on how to interact between classes here: how can I trigger an action called by clicking on a button linked to one class (the graphic user interface in my case – which does not contain any drawing code) inside another class (my drawing class – which is defined programmatically)?

Thanks!

Edited: I have tried to implement the solutions suggested below but I didn’t manage to trigger the action from the other class. I have two classes: the main view controller and a class with the drawing code. Any advice would be highly appreciated. Thanks!

//MainViewController.m
//This class has a xib and contains the graphic user interface

- (void)ImageHasChanged
{        
//do something on the GUI
}


//DrawView.m
//This class has no associated xib and contains the drawing code

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
 //I want to call ImageHasChanged from MainViewController.m here
 //How can I do this?
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:46:48+00:00Added an answer on June 9, 2026 at 4:46 pm

    Inter-class functionality is done simply by importing one class into the other, and calling an accessible method/instance variable on the import.

    For the button IBAction example in your question:

    ClassA.m (This will be imported via its header):

    #import "ClassA.h"
    @implementation ClassA
    
    // This is a class-level function (indicated by the '+'). It can't contain
    // any instance variables of ClassA though!
    +(void)publicDrawingFunction:(NSString *)aVariable { 
        // Your method here...
    }
    
    // This is a instance-level function (indicated by the '-'). It can contain
    // instance variables of ClassA, but it requires you to create an instance
    // of ClassA in ClassB before you can use the function!
    -(NSString *)privateDrawingFunction:(NSString *)aVariable {
        // Your method here...
    }
    @end  
    

    ClassB.m (This is your UI class that will call the other method):

    #import "ClassA.h"  // <---- THE IMPORTANT HEADER IMPORT!
    
    @implementation ClassB
    
    // The IBAction for handling a button click
    -(IBAction)clickDrawButton:(id)sender {
    
        // Calling the class method is simple:
        [ClassA publicDrawingFunction:@"string to pass to function"];
    
        // Calling the instance method requires a class instance to be created first:
        ClassA *instanceOfClassA = [[ClassA alloc]init];
        NSString *result = [instanceOfClassA privateDrawingFunction:@"stringToPassAlong"];
    
        // If you no longer require the ClassA instance in this scope, release it (if not using ARC)! 
        [instanceOfClassA release];
    
    }
    @end
    

    Side note: If you’re going to require ClassA a lot in ClassB, consider creating a class-wide instance of it in ClassB to re-use wherever it’s required. Just don’t forget to release it in dealloc (or maybe set it to nil in ARC) when you’re finished with it!

    Finally, please consider reading through the Apple Docs on Objective-C classes (and indeed all other sections of the documentation relevant to what you’re trying to achieve). It is a bit time-consuming, but very well invested in the long run into building your confidence as an Objective-C programmer!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A very basic question... How can I only allow the selection of one option
Very basic question - how to get one value from a generator in Python?
This might be a very basic question but it confuses me. Can two different
This is a very basic question...quite embarassing, but here goes: I have a Stopwatch
Seems,that very basic question. Anyway can't get the meaning of next definition from Spring
Very basic question here (I've just started with Python). I have a list object.
Very basic question, but I have an error in my code that can only
I have a very basic question. I would like to know if here is
very basic question: How can I find the highest or lowest value in a
This might be a very basic question but I can't find the correct command

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.