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

  • Home
  • SEARCH
  • 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 6758265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:45:46+00:00 2026-05-26T13:45:46+00:00

I created two classes. In each class there are UIButton and the related event.

  • 0

I created two classes. In each class there are UIButton and the related event. We can click on this button and the condition will change. If we click on the button in the same class and the second class status button should change. How to realize it there is an assumption to make it through the delegate, but I don’t quite understand how.enter image description here

The result should be something like the image if one of the classes button changes its status as at 1 in the other class this state changed to zero

  • 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-05-26T13:45:46+00:00Added an answer on May 26, 2026 at 1:45 pm

    I solved this problem as follows.

    I create an Objective-C protocol which contain one required method

    @protocol MyProtocolForState <NSObject>
    
    - (void)changeStateButton;
    

    Next I create class A – this class contain button which will be paired with another class (Class B)

    #import "MyProtocolForState.h"
    
    @interface A : UIViewController <MyProtocolForState>{
        id<MyProtocolForState.h> delegate;
    }
    @property (nonatomic, assign)id<MyProtocolForState.h> delegate;
    - (IBAction)touchButton:(id)sender;
    

    In implementation file I added delegate method and reaction method

    - (IBAction)touchButton:(id)sender {
        [self.view setBackgroundColor:[UIColor redColor]];
        [delegate changeMethod];
    }
    
    - (void)changeMethod{
        [self.view setBackgroundColor:[UIColor whiteColor]];
    }
    

    Next I create class B – this class contain button which will be paired with another class (Class A)

    #import "MyProtocolForState.h"
    
    @interface B : UIViewController <MyProtocolForState>{
        id<MyProtocolForState.h> delegate;
    }
    @property (nonatomic, assign)id<MyProtocolForState.h> delegate;
    - (IBAction)touchButton:(id)sender;
    

    In implementation file I added delegate method and reaction method

    - (IBAction)touchButton:(id)sender {
        [self.view setBackgroundColor:[UIColor redColor]];
        [delegate changeMethod];
    }
    
    - (void)changeMethod{
        [self.view setBackgroundColor:[UIColor whiteColor]];
    }
    

    Next i create instance class A and class B and bind them

        A * a = [[A alloc] init];
        [a.view setFrame:CGRectMake(50, 50, 100, 100)];
        B * b = [[B alloc] init];
        [b.view setFrame:CGRectMake(200, 50, 100, 100)];
        a.delegate = b;
        b.delegate = a;
        [self.window addSubview:a.view];
        [self.window addSubview:b.view];
    

    When I tap on the button in one class in other class we call delegate method and change state for view.

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

Sidebar

Related Questions

I have created a debugger visualizer in VS2008. There are two classes i've made,
I've created two classes, with one of them having an implicit cast between them:
Say I have two classes created work and workItem. CWorker *work = new CWorker();
I have two classes, a Teacher class and a Student class. In my program
Why is there an error in my code? I'm calling two classes in same
I have two classes, Foo1 and Foo2 that are not hierarchically related, so an
In the last week I've created two classes which my team expressed some concerns
I'm having trouble trying to implement a shared method/property between two classes created by
I created two tables: Publisher PK, PublisherId, int, not null, indentity +1 PublisherName, varchar(50),
I created two files in the App_GlobalResources folder: SiteResources.en-US.resx SiteResources.sp-SP.resx Both contain a value

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.