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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:18:32+00:00 2026-06-12T12:18:32+00:00

I have 2 Buttons in my View, An event must swap between the selector

  • 0

I have 2 Buttons in my View, An event must swap between the selectorof each one

in other words (Not a Code):

button1 selector = button2 selector;

button2 selector = button1 selector;

EDIT:

the event is what ever it is, but the code responsible of swap between the 2 buttons Actions is what i need

what i need is:

1-how to remove a selector and store it to use it for the other button

2-how to use a saved selector as a button selector

PS

in my code button1 and button2 have a random selectors from 9 selectors based on the user selection before entering the view containing my two buttons

  • 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-12T12:18:33+00:00Added an answer on June 12, 2026 at 12:18 pm

    This assumes you only have a single action associated with each button’s target (presumed to beself).

    NSString *oldAction1String = [[button1 actionsForTarget:self forControlEvent:UIControlEventTouchUpInside] objectAtIndex:0];
    NSString *oldAction2String = [[button2 actionsForTarget:self forControlEvent:UIControlEventTouchUpInside] objectAtIndex:0];
    
    SEL oldAction1 = NSSelectorFromString(oldAction1String);
    SEL oldAction2 = NSSelectorFromString(oldAction2String);
    
    [button1 removeTarget:self action:oldAction1 forControlEvents:UIControlEventTouchUpInside];
    [button1 addTarget:self action:oldAction2 forControlEvents:UIControlEventTouchUpInside];
    
    [button2 removeTarget:self action:oldAction2 forControlEvents:UIControlEventTouchUpInside];
    [button2 addTarget:self action:oldAction1 forControlEvents:UIControlEventTouchUpInside];
    

    There are ways around so much duplicated code but I felt this way was much more readable. Finally, this solution truly swaps actions based on the run time situation rather than rely on assigning specific actions at compile time, which should meet your updated requirement. Hope this helps!

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

Sidebar

Related Questions

On my view, I used to have few buttons and each button had an
I have created an alert view with two buttons using the following code: UIAlertView
I have a FrameLayout view which contains one (MapView-like) control and some additional buttons
I have a custom dialog with one editText view and two buttons ok and
i have one code which moves the uiimage on touch-event it's like this: -(void)touchesBegan:(NSSet
I am creating a split view ipad app. I have four buttons in the
I have an view in my App which has a number of buttons based
I have a simple Backbone view which uses jQuery UI's buttons. For example I
I have a list view in jQuery Mobile with delete buttons in them. <ul
I have 4 views and control these view with 4 buttons, I am bit

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.