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 7924135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:34:52+00:00 2026-06-03T17:34:52+00:00

Given : classA with its delegate classB has a button on it classA.h @protocol

  • 0

Given :

  1. classA with its delegate
  2. classB has a button on it
classA.h

@protocol classADelegate <NSObject>
- (void)method:(NSString *) name;
@end
@interface StoreChooser : UIViewController
@end
------------------------------------------------------
classA.m
-(IBAction)buttonCliked{
     // invoke delegate method from classA at here

}

classB.h
@interface classB : UIViewController <classADelegate>
@end

------------------------------------------------------
// Conform delegate of classA
classB.m
- (void)method:(NSString *) name {

}
@end
——————————————————

My goal : I need classB to invoke a method delegate from classA in buttonClicked action

Question : what should I do to achieve my goal.

  • 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-03T17:35:13+00:00Added an answer on June 3, 2026 at 5:35 pm

    Just to make sure that we are on the same page 🙂

    If ClassA has a delegate ClassADelegate. What this means is that when some “event” occurs in ClassA, ClassA will want to notify some other class via its delegate that the “event” occurred – ClassB. ClassA will do this via its delegate – ClassADelegate.

    For this to happen, ClassB will have to let ClassA know that it will be acting as ClassA‘s delegate. ClassB will have to “conform” to ClassA‘s protocol by implementing all of the methods listed in the protocol that not marked as @optional.

    In code, you could do this:

    // ClassA's delegate
    
    @protocol ClassADelegate <NSObject>
    - (void) didDoSomethingCool:(NSString *) name;
    @end
    
    // ClassA definition
    
    @interface ClassA
    // We'll use this property to call the delegate.
    // id<XXX> means that which ever class is assigned to id MUST conform to XXX
    @property (nonatomic, assign) id<ClassADelegate> classADelegate; 
    - (void) doSomething;
    @end
    
    // Class A implementation
    
    @implementation ClassA
    
    @synthesize classADelegate;
    
    - (void) doSomething
    {
      // Do cool things here.
      // Now call delegate, in this example, this will be ClassB
      [classADelegate didDoSomethingCool:@"Hello from Class A"];
    }
    

    Now we need to wire-up ClassB so that it can be notified that something happened in ClassA:

    // ClassB definition
    
    @interface ClassB<ClassADelegate>
    // ClassB<ClassADelegate> lets the compiler know that ClassB is required to have all the 
    // non-optional method that are listed in ClassADelegate. In short, we say that
    // ClassB conforms to the ClassADelegate.
    {
      ClassA *_classA;
    }
    @end
    

    Now somewhere in ClassB‘s implementation file we have the following.

    // ClassB implementation
    
    @implementation ClassB
    
    - (id) init
    {
      self = [super init];
      if(self)
      {
        // Just quickly creating an instance of ClassA.
        _classA = [ClassA new];
        // This is were we tell ClassA that ClassB is its delegate.
        _classA.classADelegate = self;
      }
      return self;
    }
    
    - (void) dealloc
    {
      [_classA release];
      [super dealloc]; 
    }
    
    - (void) didDoSomethingCool:(NSString *) name
    {
      // This is the method that ClassA will be calling via the 
      // [classADelegate didDoSomethingCool:@"Hello from Class A"] method call.
    }
    
    @end
    

    I hope this helps 🙂

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

Sidebar

Related Questions

Given: class A { public void m(List l) { ... } } Let's say
Given a class such as: class Person { private: char *name; public: Person() {
Given a class: [DataContract] public sealed class ChangedField { [DataMember(Name=I)] public ushort FieldId {
I have a ProgressBarWindow which has a progressbar and a cancel button on it
I have this code in my table view controller (and delegate): - (void)tableView:(UITableView *)tableView
I have a class such as the following: @XmlRootElement(name = a) public class ClassA
I have an external library which has a method which performs a long running
Given: class example { public: std::vector<std::vector<int>> a; int b; } func() { example e;
i have been given class with int variables x and y in private, and
I understand that CoCreateInstance finds the COM server for the given class id, creates

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.