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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:23:54+00:00 2026-06-10T19:23:54+00:00

I am adding Radio Buttons in custom cell of UITableView and calling a method

  • 0

I am adding Radio Buttons in custom cell of UITableView and calling a method on it to changes its image or background Image. I able to set Selected button Image from sender but I want to make other buttons to their original position which I am unable to set it, as below functionality need to be look like proper Radio buttion in a cell

I am also facing problem in fetching proper Index Path in this method – (void) TableRadioButtonSelection:(id)sender;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *RadioIdentifier = @"RadioCellIdentifier";

        RadioBtnCell *myRadiocell = (RadioBtnCell *)[tableView dequeueReusableCellWithIdentifier:RadioIdentifier];
        if(myRadiocell == nil) {
            [[NSBundle mainBundle] loadNibNamed:@"RadioBtnCell" owner:self options:nil];
            myRadiocell = radioCell;

            //[myRadiocell.radioBtn1 setBackgroundImage:[UIImage imageNamed:@"radiobtn.png"] forState:UIControlStateNormal];
            myRadiocell.radioBtn1.tag = ButtonTag;
            //[myRadiocell.radioBtn2 setBackgroundImage:[UIImage imageNamed:@"radiobtn.png"] forState:UIControlStateNormal];
             myRadiocell.radioBtn2.tag = ButtonTag1;
            //[myRadiocell.radioBtn3 setBackgroundImage:[UIImage imageNamed:@"radiobtn.png"] forState:UIControlStateNormal];
             myRadiocell.radioBtn3.tag = ButtonTag2;
            myRadiocell.tag = RadioTag;

            [myRadiocell.radioBtn1 addTarget:self action:@selector(TableRadioButtonSelection:) forControlEvents:UIControlEventTouchUpInside];
            [myRadiocell.radioBtn2 addTarget:self action:@selector(TableRadioButtonSelection:) forControlEvents:UIControlEventTouchUpInside];
            [myRadiocell.radioBtn3 addTarget:self action:@selector(TableRadioButtonSelection:) forControlEvents:UIControlEventTouchUpInside];

            myRadiocell.backgroundView.backgroundColor = [UIColor clearColor];
            self.radioCell = nil;

        }

return  myRadiocell;

}

- (void) TableRadioButtonSelection:(id)sender {

    //RadioBtnCell *buttonCell = (RadioBtnCell*)[[btn superview] superview];

    RadioBtnCell *cell = (RadioBtnCell *)[self.questionTblView viewWithTag:RadioTag];
    UIButton *mybtn = (UIButton *)[cell.contentView viewWithTag:ButtonTag];
    UIButton *mybtn1 = (UIButton *)[cell.contentView viewWithTag:ButtonTag1];
    UIButton *mybtn2 = (UIButton *)[cell.contentView viewWithTag:ButtonTag2];

    [mybtn setBackgroundImage:[UIImage imageNamed:@"radiobtn.png"] forState:UIControlStateNormal];
    [mybtn1 setBackgroundImage:[UIImage imageNamed:@"radiobtn.png"] forState:UIControlStateNormal];
    [mybtn2 setBackgroundImage:[UIImage imageNamed:@"radiobtn.png"] forState:UIControlStateNormal];

     //NSLog(@"%@",[cell subviews]);
    UIView* mysubview = [cell.contentView viewWithTag:ButtonTag]; // Make sure your UITextField really *is* the last object you added.
    UIView* mysubview1 = [cell.contentView viewWithTag:ButtonTag1];
    UIView* mysubview2 = [cell.contentView viewWithTag:ButtonTag2];

   // I am unable to set Image of other buttons apart from sender.

    //for(UIView *item in [mysubview subviews]) {

        if ([mysubview isKindOfClass:[UIButton class]]) {
            UIButton *newBtn = (UIButton*)mysubview;
            UIButton *newBtn1 = (UIButton*)mysubview1;
            UIButton *newBtn2 = (UIButton*)mysubview2;

            NSLog(@"OK %@",newBtn);
            //[newBtn setBackgroundImage:[UIImage imageNamed:@"radiobtn.png"] forState:UIControlStateNormal];
            [newBtn setImage:[UIImage imageNamed:@"radiobtn.png"] forState:UIControlStateNormal];
            [newBtn1 setImage:[UIImage imageNamed:@"radiobtn.png"] forState:UIControlStateNormal];
            [newBtn2 setImage:[UIImage imageNamed:@"radiobtn.png"] forState:UIControlStateNormal];

        }
    //}

    NSIndexPath *indexPath = [self.questionTblView indexPathForCell:cell]; 
    NSLog(@"%d",indexPath.row);

    //  Below code is setting Image of selected Button properly as checked but above code for making button onto original state is not setting button image or background image

    UIButton *btn = (UIButton *)sender;
    [btn setImage:[UIImage imageNamed:@"radiobtn_chk.png"] forState:UIControlStateNormal];
    //[btn setBackgroundImage:[UIImage imageNamed:@"radiobtn_chk.png"] forState:UIControlStateNormal];
}
  • 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-10T19:23:56+00:00Added an answer on June 10, 2026 at 7:23 pm

    try changing this line to this;-

    RadioBtnCell *cell = (RadioBtnCell *)[self.questionTblView viewWithTag:RadioTag];
    
    to
    
         RadioBtnCell *cell = (RadioBtnCell *)[self.questionTblView cellForRowAtIndexPath:*indexPathofthecell*];
    

    In this way you can access the table view cell.After that you can get the button from cell content views and do further coding.

    Suppose if you do not know the indexPath then you can create the indexPath fromm the rowNumber of the table view(I think you have stored the table row number in RadioTag, if yes so you can use this field as a parameter).

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

Sidebar

Related Questions

i am adding collection of radio buttons to my page using jQuery below $(document).ready(function()
I'm adding buttons to a radio field dynamically, the function that adds the elements
I have 3 radio buttons on my page. They are loaded by calling a
http://www.asp.net/data-access/tutorials/adding-a-gridview-column-of-radio-buttons-cs Please refer the above link. How to select the RadioButton programatically?
I have a set of radio buttons that are for certain products. I am
I am essentially adding radio-buttons functionality to buttons with the class tagbutton. There is
1. Problem I am adding a shoutcast radio to website (appeding this code to
Adding the row one by one in the button click.. (i tried but its
Adding functionality to a class can be done by adding a method or by
Adding member variables to a class certainly boosts the memory footprint of its instances

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.