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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:16:46+00:00 2026-05-27T03:16:46+00:00

I have a table view. I originally used the cell’s textLabel to handle this,

  • 0

I have a table view. I originally used the cell’s textLabel to handle this, but that didnt work, so i added a UILabel to each cell programatically and i have two buttons a add button and a subtract button which basically counts up or down when pressed. (goes up or down by 1) The methods for the two buttons are:

 - (IBAction)addLabelText:(id)sender{    
   cellLabel.text = [NSString stringWithFormat:@"%d",[cellLabel.text intValue] +1];

}  

- (IBAction)subtractLabelText:(id)sender
{
    if ( [[cellLabel text] intValue] == 0){ 
        cellLabel.text = [NSString stringWithFormat:@"%d",[cellLabel.text intValue] +0];
    }
    else{
        cellLabel.text = [NSString stringWithFormat:@"%d",[cellLabel.text intValue] -1];
    }
}

when i pressed the buttons, and added multiple cells, the buttons interfered with each other’s labels. So i added this line of code to each of the above methods. :

    cellLabel = (UILabel*)[sender superview];    

in hopes that it would fix the problem. But it actually added i believe the cells textLabel again. Here is a photo of what it looks like before and after i press one of the buttons with the new line added.

enter image description here

After:

enter image description here

any help with fixing the buttons interfering with each other cells UILabel’s please help!! 😀 Thanks

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

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
     {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
         newBtn = [[UIButton alloc]init];
         newBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
         [newBtn setFrame:CGRectMake(280,10,25,55)];
         [newBtn addTarget:self action:@selector(subtractLabelText:) forControlEvents:UIControlEventTouchUpInside];
         [newBtn setTitle:@"-" forState:UIControlStateNormal];
         [newBtn setEnabled:YES];
         [cell addSubview:newBtn];

         subBtn = [[UIButton alloc]init];
         subBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
         [subBtn setFrame:CGRectMake(250,10,25,55)];
         [subBtn addTarget:self action:@selector(addLabelText:) forControlEvents:UIControlEventTouchUpInside];
         [subBtn setTitle:@"+" forState:UIControlStateNormal];
         [subBtn setEnabled:YES];
         [cell addSubview:subBtn];

         cellLabel = [[UILabel alloc]init];
         [cellLabel setFrame:CGRectMake(85, 22, 27, 27)];
         [cellLabel setText:@"1"];
         [cell addSubview:cellLabel];**
    } 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.imageView.image = [imageArray objectAtIndex:indexPath.row];    
   // cell.textLabel.text = [cells objectAtIndex:indexPath.row];
    **if ([cell.imageView.image  isEqual:[UIImage imageNamed:@"paddle5.png"]]) {
        [cellLabel setFrame:CGRectMake (195, 22, 30, 30)];
    }
    if ([cell.imageView.image  isEqual:[UIImage imageNamed:@"paddle4.png"]]) {
        [cellLabel setFrame:CGRectMake (170, 22, 30, 30)];
    }
    if ([cell.imageView.image  isEqual:[UIImage imageNamed:@"paddle3.png"]]) {
        [cellLabel setFrame:CGRectMake (140, 22, 30, 30)];
    }
    if ([cell.imageView.image  isEqual:[UIImage imageNamed:@"paddle2.png"]]) {
        [cellLabel setFrame:CGRectMake (110, 22, 30, 30)];
    }**
return cell;
}
  • 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-27T03:16:47+00:00Added an answer on May 27, 2026 at 3:16 am

    set tag to cell whet you cnfigurating it:
    in my table I have some sections and some cells in every section. So, cells from first (0) section has tag 0…9999. from second – 10000…19999 adn so on. I mean tag of cell = 10000*number of section PLUS number of raw of this cell in ths section. then, to calculate what exacly is ths cell, I see how many 10000 tag has, to calculate from what sectiont it is, and how many >10000 tag has to calculate from what raw it is. So, I have section and raw from my table view.

    cell.contentView.tag = indexPath.row+10000*indexPath.section; //or any you like
    [cell.contentView addSubview:button]; //adding your button
    

    then, in button’s callback:

    int row=0;
    int section=0;
    long tag = [sender superview].tag;
    NSLog(@"tag: %ld", tag);
    for (int i = 0; i<[data count]; i++) {
        if (tag>=10000) 
        {
            tag-=10000;
            section++;
        }
        else i = [data count];
    }
    row = tag;
    
    NSIndexPath *indexPath = [[NSIndexPath alloc] initWithIndex:section];
    indexPath = [indexPath indexPathByAddingIndex:row];
    [tableView cellForRowAtIndexPath:indexPath];
    

    now, you have full access to your cell. use calculated raw and section ta get access to cell.

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

Sidebar

Related Questions

I have a table view controller with custom cells. In those cells i added
I have a table view that I am customizing and I am adding a
I have a table view that is managed by an NSFetchedResultsController. I am having
I have Grouped Table View in which I want to display Contact details. But
I have one table view that should be filtered by values of search field
I have my table view and the cells within it have the UILongPressGestureRecognizer added
I have a grouped table view that contains 3 sections and each row per
The situation is this: a table that is used in a query (name it
I have a table view that pushes to a detail view controller. From the
I have application with following design: Table View that lists documents. And ViewController where

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.