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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:11:38+00:00 2026-06-06T19:11:38+00:00

I have dynamically created some list of RadioButtons with some values. pro grammatically I

  • 0

I have dynamically created some list of RadioButtons with some values. pro grammatically I changed the button state and changed the image for selected and unselected. but the problem is i can select the all radioButtons at same time. actually I need to select one at a time.
when I clicked the next RadioButton, previously selected button state should be changed to non-selected.

Here is my code, I tried with changing image, but …some problem with my code.

   RadioButton = [UIButton buttonWithType:UIButtonTypeCustom];
   [RadioButton setFrame:CGRectMake(0.0f, 0.0f, 20, 20)];
   [RadioButton setCenter:CGPointMake(116.0,p1)];
   [RadioButton setSelected:NO];
   [RadioButton setImage:[UIImage imageNamed:@"uncheck.png"] forState:UIControlStateNormal];
   [RadioButton addTarget:self action:@selector(RadioButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
   [self.scrollView addSubview:RadioButton];




  -(void)RadioButtonTapped:(id)sender
    {


       UIButton *RadioButton1 = (UIButton*)sender ;

      [self radiobuttonAction:RadioButton1];
    }

 -(void)radiobuttonAction:(UIButton *)Button
    {

       if(![Button isSelected])
         {


            [Button setSelected:YES]; 
            [Button setImage:[UIImage imageNamed:@"radio_active.png"] forState:UIControlStateSelected]; //not working, button image is not changing 
        } 
     else
        { 
            [Button setSelected:NO]; 
            [Button setImage:[UIImage imageNamed:@"radio_inactive.png"] forState:UIControlStateNormal];
        }


 }

where can I change the image of previously selected button.

thanks in advance

  • 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-06T19:11:40+00:00Added an answer on June 6, 2026 at 7:11 pm

    Deselect all the buttons when you select one. If you have buttons in your scroll view you can user this code:

    //Your Method
    -(void)RadioButtonTapped:(id)sender
    {
      UIButton *RadioButton1 = (UIButton*)sender;
      [self deselectAll];
      [self radiobuttonAction:RadioButton1];      
    }
    
    - (void) deselectAll : (UIScrollView *) scrollView{
      NSArray *viewArray = [scrollView subviews];
      for (UIView *v in viewArray){
      if([v isKindOfClass:[UIButton class]]){
            [((UIButton *)v) setSelected:NO];
      }
     }
    }
    

    EDIT: But if you want to give it real radio button effect (in which one is always selected, and only one is selected) it will be more easy to you. Use following code:

     //A globle refButton
      UIButton *refButton = nil;
     //Set image for both state:
    [RadioButton setImage:[UIImage imageNamed:@"uncheck.png"] forState:UIControlStateNormal];
    [RadioButton setImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateSelected];
    
     //make any of above default select: may be the last one and pass that to `refButton`
     refButton = RadioButton;
    
    
    
     //Your Method
    -(void)RadioButtonTapped:(id)sender
    {
      [refButton setSelected:NO];
      refButton = (UIButton*)sender;
      [refButton setSelected:YES];      
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that dynamically creates a new button through JavaScript that when
I have a dynamically created list. Items from the list should be able to
I have created some enums as .dll dynamically using data from database. I am
I got a bunch dynamically created regressions stored in some list called regressions .
I have a dynamically created list of labels and I am using GestureRecognizer for
I have dynamically created the buttons in a div. And binding the click and
I have dynamically created WrapPanel (_wp) with several Borders. And I need create handler
I am going to make a GUI that will have dynamically created sets of
I have a dynamically created DataGridView that has a valid DataSource with one row
I have a dynamically created table which in the last <td> there is a

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.