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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:21:21+00:00 2026-05-26T02:21:21+00:00

Ok i have a table view that can add and delete cells. For each

  • 0

Ok i have a table view that can add and delete cells. For each cell thats added, it gets two buttons in the cell an add and subtract button which adds 1 and subs 1 from the cell’s textLabel. But when i press on 1 cells button, it subs from another cells textLabel. Here is my cellForRow method:

- (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];
} 
cell.imageView.image = [imageArray objectAtIndex:indexPath.row];    
cell.textLabel.text = [cells objectAtIndex:indexPath.row];

newBtn = [[UIButton alloc]init];
newBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[newBtn setFrame:CGRectMake(195,20,55,35)];
[newBtn addTarget:self action:@selector(subtractLabelText:)   
forControlEvents:UIControlEventTouchUpInside];
[newBtn setTitle:@"-" forState:UIControlStateNormal];
[cell addSubview:newBtn];

return cell;
}

This next method is the method is the one i hooked up to the subtract button:

- (IBAction)subtractLabelText:(id)sender{

if ( [[cell.textLabel text] intValue] == 0){ 
[newBtn setEnabled:NO];
}
else{
cell.textLabel.text = [NSString stringWithFormat:@"%d",[cell.textLabel.text  
intValue] -1];
    }
}

Please help!! Thanks so much! 😀

  • 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-26T02:21:21+00:00Added an answer on May 26, 2026 at 2:21 am

    You should pass the cell as the argument of subtractLabelText:, otherwise this function does not know which cell its accessing.


    The simplest thing that comes to mind for me is to do is to add in a line defining the cell:

    - (IBAction)subtractLabelText:(id)sender{
    
    UITableViewCell *cell = (UITableViewCell*)[sender superview]; // <-- ADD THIS LINE
    
    if ( [[cell.textLabel text] intValue] == 0){ 
    [newBtn setEnabled:NO];
    }
    else{
    cell.textLabel.text = [NSString stringWithFormat:@"%d",[cell.textLabel.text  
    intValue] -1];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can add and delete cells to my table view. How to have two
Currently, I have a table view that the user can add items and delete
On each cell of my table view I want to have a bar that
I have a self referencing table in Oracle 9i, and a view that gets
I have a UItableView I can add and delete cells. I can change the
I have a tableview that is blank by default. User can add cells to
I have a UITableView and i can add and delete cells. I also have
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 an MVC application view that is generating quite a large HTML table

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.