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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:19:50+00:00 2026-05-26T14:19:50+00:00

I want to accomplish touching a UIButton and having code run in a different

  • 0

I want to accomplish touching a UIButton and having code run in a different class than the owner.

I realize I can do a touchUpInside to the button’s owner (ClassA) and then call the method inside ClassB that I want called, but is there any way to expedite this?

ideas:

  • have ClassB be the delegate for the ClassA->UIButton

  • set the touchUpInside call in programming to used the function inside ClassB

I’m not sure how to accomplish either of these ideas 🙁 Input is mas appreciated!

  • 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-26T14:19:51+00:00Added an answer on May 26, 2026 at 2:19 pm

    One option is to set the button up using

    [myButton addTarget:yourOtherClass action:@selector(mySelector:) forControlEvents:UIControlEventTouchUpInside];
    

    but this is a bit dangerous because target is not retained so you could send the message to a deallocated object.

    You could instead set up a protocol

    MyController.h
    
    @protocol MyControllerDelegate
    - (void)myController:(MyController *)controller buttonTapped:(UIButton *)button;
    @end
    
    @interface MyController : UIViewController
    
    @property (nonatomic, assign) id <MyControllerDelegate> delegate;
    
    - (IBAction)buttonTapped:(UIButton *)button;
    
    @end
    

    Then in your implementation

    MyController.m
    
    - (IBAction)buttonTapped:(UIButton *)button
    {
        if ([self.delegate respondsToSelector:@selector(myController:buttonTapped:)]) {
          [self.delegate myController:self buttonTapped:button];
        }
    }
    

    As the method defined in the protocol was not optional I could have instead done a check for (self.delegate) to make sure it is set instead of respondsToSelector.

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

Sidebar

Related Questions

I searched and tried a lot, but I can't accomplish it as I want..
What I want to accomplish is simple. I want a button's text to change
I want to accomplish the same thing with code that Flash's Align - Align
Can anyone suggest best method for what I want to accomplish? I have an
I want to accomplish a GLSL Shader, that can texture and color my vertex
Here is an example of what I want to accomplish and how: class MyClass
I use CoolTrayIcon component,but I can modify it by hand.What I want to accomplish
I have this htaccess code. What I want to accomplish is be able to
For what I want to accomplish, I can use either createElement() or innerHTML and
I can't wrap my head around how to accomplish rendering this public class Shape{}

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.