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.

After:

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;
}
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.
then, in button’s callback:
now, you have full access to your cell. use calculated
rawandsectionta get access to cell.