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

  • Home
  • SEARCH
  • 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 9193641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:12:54+00:00 2026-06-17T21:12:54+00:00

In UITableViewCell there are different buttons and when I click on any button its

  • 0

In UITableViewCell there are different buttons and when I click on any button its action is being performed on all the cells, but I want that when I press the button then the action will be shown on the label of the same cell, I know I need to put them in array but how…?

when I click on the button one value is being incremented and it should be shown on the label of the same cell
here is the code:-

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        likeShow=[[UILabel alloc]initWithFrame:CGRectMake(0, 160, 80, 20)];
        likeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
       [likeBtn addTarget:self action:@selector(likeFn) forControlEvents:UIControlEventTouchUpInside];
        likeBtn.frame=CGRectMake(0, 110, 90, 50);
        [likeBtn setTitle:@"Like" forState:UIControlStateNormal];
        [likeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [cell addSubview:likeBtn];
        [cell addSubview:likeShow];
        return cell;
}

This is the action of the button

-(void)likeFn{
            NSString *str;
            NSMutableString *mystring=[NSMutableString string];
            likeCount++;
            str =[NSString stringWithFormat:@"%d",likeCount];
            NSString *world = @"Like";
            NSString *helloWorld = [world stringByAppendingString:str];
            likeShow.text=helloWorld;        
}
  • 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-17T21:12:56+00:00Added an answer on June 17, 2026 at 9:12 pm

    Try the below code

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    NSString *CellIdentifier = [NSString stringWithFormat:@"Cell-%d",indexPath.row];
    
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    
    if (cell == nil)
    {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        //[cell clearsContextBeforeDrawing];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    int lbltag = 1000;
    
    UIButton *likeBtn = nil;
    UILabel *likeShow = nil;
    
    if ([cell viewWithTag:lbltag])
    {
        likeShow = (UILabel*)[cell viewWithTag:lbltag];
    }
    else
    {
        likeShow=[[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80, 20)] autorelease];
        likeShow.text = [NSString stringWithFormat:@"%d likes",[[_marrTest objectAtIndex:indexPath.row] intValue]];
        likeShow.tag = lbltag;
        [cell addSubview:likeShow];
    }
    
    if ([cell viewWithTag:indexPath.row+1])
    {
        likeBtn = (UIButton*)[cell viewWithTag:indexPath.row+1];
    }
    else
    {
        likeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        likeBtn.tag = indexPath.row+1;
        [likeBtn addTarget:self action:@selector(likeFn:) forControlEvents:UIControlEventTouchUpInside];
        likeBtn.frame=CGRectMake(90, 0, 90, 50);
        [likeBtn setTitle:@"Like" forState:UIControlStateNormal];
        [likeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [cell addSubview:likeBtn];
    
    }
    
    return cell;
    }
    
    -(void)likeFn:(UIButton*)btnClicked
    {
    NSString *strLikes = [_marrTest objectAtIndex:btnClicked.tag-1];
    int likeCount = [strLikes intValue] + 1;
    [_marrTest replaceObjectAtIndex:btnClicked.tag-1 withObject:[NSString stringWithFormat:@"%d",likeCount]];
    
    NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:btnClicked.tag-1 inSection:0];
    
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:selectedIndexPath];
    
    UILabel *requiredLabel = (UILabel*)[cell viewWithTag:1000];
    
    NSString *str = requiredLabel.text;
    
    //str = [str stringByAppendingFormat:@"selected %@", str];
    requiredLabel.text = @"";
    requiredLabel.text = [NSString stringWithFormat:@"%d likes",[[_marrTest objectAtIndex:btnClicked.tag-1] intValue]];
    
    //do what ever you want with the label
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys i have cells in tableview, but there are two different UIButtons to
Is there any way to access the owning UITableView from within a UITableViewCell ?
I have customized a UITableViewCell and I want to implement swipe to delete. But
I have an application with multiple views. I can click on different buttons to
I have a UITableViewCell with 3 checkmark buttons. Each checkmark button is a custom
I would want to create a custom UITableViewCell which should have a different appearance
I have some table cells displaying different time. I want the time to be
I want to display different UITableViewCell s depending on what content is available .
i have a grouped tableview which contains 3 sections,i want to add different buttons
Is there a way to force a custom UITableViewCell to be released instead of

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.