Я хочу изменить значение кнопки-элемента при нажатии кнопки плюс и минус ячейки tableview.Это моя ячейка таблицы для кода метода индекса строки.
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [menuTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
UIButton *minusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
minusBtn.frame= CGRectMake(400, 5,30,30);
minusBtn.tag = indexPath.row;
[minusBtn setImage:[UIImage imageNamed:@"removeButan.png"] forState:UIControlStateNormal];
[minusBtn addTarget:self action:@selector(minusAction:) forControlEvents:UIControlEventTouchUpInside];
UIButton *plusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
plusBtn.frame= CGRectMake(500, 5,30,30);
plusBtn.tag = indexPath.row;
[plusBtn setImage:[UIImage imageNamed:@"Addbutton.png"] forState:UIControlStateNormal];
[plusBtn addTarget:self action:@selector(plusAction:) forControlEvents:UIControlEventTouchUpInside];
UIButton *itemBtn = [UIButton buttonWithType:UIButtonTypeCustom];
itemBtn.frame= CGRectMake(450, 5,30,30);
itemBtn.tag = indexPath.row;
[itemBtn setBackgroundImage:[UIImage imageNamed:@"number_butan_1.png"] forState:UIControlStateNormal];
[itemBtn setTitle:totalItem forState:UIControlStateNormal];
[itemBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
UIButton *addToCart = [UIButton buttonWithType:UIButtonTypeCustom];
addToCart.frame= CGRectMake(580,5,30,30);
addToCart.tag = indexPath.row;
addToCart.font = [UIFont systemFontOfSize:14];
[addToCart setImage:[UIImage imageNamed:@"cart.png"] forState:UIControlStateNormal];
[addToCart addTarget:self action:@selector(addToCartAction:) forControlEvents:UIControlEventTouchUpInside];
UIButton *infoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
infoBtn.frame= CGRectMake(630, 5,30,30);
infoBtn.tag = indexPath.row;
[infoBtn setImage:[UIImage imageNamed:@"info.png"] forState:UIControlStateNormal];
[infoBtn addTarget:self action:@selector(displayDetailView:) forControlEvents:UIControlEventTouchUpInside];
// lblTitle.text = [nameArray objectAtIndex:indexPath.row];
cell.primaryLabel.text = [appDelegate.nameArray objectAtIndex:indexPath.row];
cell.secondaryLabel.text = [appDelegate.sortDetailArray objectAtIndex:indexPath.row];
cell.priceLabel.text = [appDelegate.rateArray objectAtIndex:indexPath.row];
[cell.contentView addSubview:minusBtn];
[cell.contentView addSubview:plusBtn];
[cell.contentView addSubview:addToCart];
[cell.contentView addSubview:itemBtn];
[cell.contentView addSubview:infoBtn];
return cell;
}
- (IBAction)plusAction:(id)sender{
// Hat* obj = ((UIButton *)sender).tag;
// NSNumber* hatId = obj.idValue;
UITableViewCell *cell=(UITableViewCell*)[[sender superview] superview];
UITableView *table=(UITableView*)[cell superview];
NSIndexPath *path=[table indexPathForCell:cell];
int value = [totalItem intValue];
value++;
totalItem = [NSString stringWithFormat:@"%d",value];
NSLog([NSString stringWithFormat:@"%@",totalItem]);
[menuTableView reloadData];
}
- (IBAction)minusAction:(id)sender{
UIView *contentView = [sender superview];
UITableViewCell *cell=(UITableViewCell*)[[contentView superview] superview];
UITableView *table=(UITableView*)[cell superview];
NSIndexPath *path=[table indexPathForCell:cell];
NSUInteger buttonRow = [[menuTableView
indexPathForCell:cell] row];
int value = [totalItem intValue];
value--;
totalItem = [NSString stringWithFormat:@"%d",value];
NSLog([NSString stringWithFormat:@"%@",totalItem]);
[menuTableView reloadData];
}
Я пытаюсь это сделать, но не работаю. Изменить все значения строки