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

The Archive Base Latest Questions

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

I have two buttons inside sectioned tableview cell thumbs up and thumbs down. Initially

  • 0

I have two buttons inside sectioned tableview cell thumbs up and thumbs down. Initially image of both button is not selected. When I select thumbs up button its image become thumbs up selected and other one become thumbsdown not selected and vice versa.

//Number of sections
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{
    NSLog(@"mod:numberOfSectionsInTableView");
    NSLog(@"[preferences count]=%d",[preferences count]);
    return  [preferences count];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.choices count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexpath
{
    NSLog(@"cellForRowAtIndexPath: DISPLAY TEST");  
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        NSLog(@"Text is: %@", [choices objectAtIndex:indexpath.row]);                   
        NSLog(@"CHOICE AT INDEX PATH IS: %@",[choices objectAtIndex:indexpath.row %[choices count]]);
        cell.textColor = [UIColor whiteColor];
        cell.backgroundColor = [UIColor blackColor];


        // Thumbs up button.
        //UIButton *thumbsUp = [[UIButton alloc]init];  
        thumbsUp = [UIButton buttonWithType:UIButtonTypeCustom];                        
        [thumbsUp setTag:(indexpath.row+(indexpath.section * 50))];
        [thumbsUp addTarget:self action:@selector(thumbUp_ButtonClicked:event:)
            forControlEvents:UIControlEventTouchUpInside];     
        [thumbsUp setTitle:@"" forState:UIControlStateNormal];
        thumbsUp.frame = CGRectMake(150.0, 20, 20, 15);
        [thumbsUp setBackgroundImage:[UIImage imageNamed:@"thumbsup_not_selected.png"]
     forState:UIControlStateNormal];

        //NSLog(@"------------------>TAG TEST : %d",(indexpath.row+(indexpath.section * 50)));
        [cell.contentView addSubview:thumbsUp];

        // Thumbs down button

        thumbsDown = [UIButton buttonWithType:UIButtonTypeCustom];
        [thumbsDown addTarget:self  action:@selector(thumbDown_ButtonClicked:event:)
            forControlEvents:UIControlEventTouchUpInside];
        [thumbsDown setTitle:@"" forState:UIControlStateNormal];
        thumbsDown.frame = CGRectMake(200, 20, 20, 15);

        [thumbsDown setTag:indexpath.row+120];
        [cell.contentView addSubview:thumbsDown];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];


        [thumbsDown setBackgroundImage:[UIImage imageNamed:@"thumbsdown_not_selected.png"]
            forState:UIControlStateNormal];
    }

    NSLog(@"------------> TAG TEST %d",thumbsUp.tag);
    cell.text = [choices objectAtIndex:(indexpath.row % [choices count])];


    NSLog(@"HELLO FOR TESTING");
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
    if (sectionTitle == nil) {
        return nil;
    }

    // Create label with section title
    UILabel *label = [[[UILabel alloc] init] autorelease];
    label.frame = CGRectMake(15, 10, 300, 25);
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor blackColor];
    label.shadowColor = [UIColor whiteColor];
    label.shadowOffset = CGSizeMake(0.0, 1.0);
    label.font = [UIFont boldSystemFontOfSize:16];
    label.textAlignment = UITextAlignmentLeft;
    label.text = sectionTitle;


    // Create header view and add label as a subview
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(12, 0, 300, 60)];
    [view autorelease];
    [view addSubview:label];
    //[view addSubview:segmentedControl];
    view.backgroundColor = [UIColor grayColor];
    return view;
}

//Thumbs Up Button Action

- (IBAction)thumbUp_ButtonClicked:(id)sender event:(id)event
{
    NSLog(@"Thumbs Up Check!");


    UIButton *button = (UIButton *)sender;
    UITableViewCell *cell = (UITableViewCell *) [[button superview] superview];


    NSIndexPath *indexPath = [myTable indexPathForCell:cell];
    NSLog(@"indexpath =%d",indexPath.row);
    //[button setTag:indexPath.row+(indexPath.section * 50)];

    int cTag = [sender tag];
    NSLog(@"------>TAG : %d", cTag);
    NSLog(@"------> Calculated TAG %d",indexPath.row+(indexPath.section * 50));
    if(cTag == (indexPath.row+(indexPath.section * 50)))
    {
        NSLog(@"BUTTON COUNT:");
        [button setBackgroundImage:[UIImage imageNamed:@"thumbsup_selected.png"]
            forState:UIControlStateNormal];
    }enter code here


    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;

    //int row = button.tag;

    NSLog(@"SECTION IS:%d",section);
    NSLog(@"ROW IS: %d",row);


    NSArray *array = cell.contentView.subviews;
    NSLog(@"NUMBER OF OBJECTS: %d",[array count]);
    UIButton *test = (UIButton *)[array objectAtIndex:2];

    [test setBackgroundImage:[UIImage imageNamed:@"thumbsdown_not_selected.png"]forState:UIControlStateNormal];

}

Due to issue with tag of button while I change image of one button several buttons are changing.

If any one can please find a solution it will be helpful…. tag is setting for buttons in sections which we can view.

If the Tableview is not sectioned its working well.

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

    Your problem might be the fact that you’re setting the variable only if the cell is newly created. Perhaps the sectioning has an impact on how many cells are affected. Try pulling your thumbs up / thumbs down code out of the if (cell == nil) block and see if that has an effect.

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

Sidebar

Related Questions

I have two buttons inside sectioned tableview cell thumbs up and thumbs down. Initially
I have two buttons inside sectioned tableview cell thumbs up and thumbs down. Initially
I have two buttons with the same ID: <button type=submit onclick=//do something id=theID>button 1</button>
I need to have a single <li> element which has two buttons inside of
I have two radio buttons both set as async triggers for an update panel
I have a HorizontalFieldManager with two buttons inside it. The buttons need to be
I have two buttons What I would like to do is inside button1_click() which
I have created two buttons using the following XAML code. <Button x:Name=Button1 Width=100 Content=Button1
I have a form with a dropdownlist, two buttons, and two Listboxes inside an
I have two ListBoxes, one inside another. And both ListBoxes will have items dynamically

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.