ios tableviewcell点击会触发哪些方法
1个回答
展开全部
想到的方法是:在初始化cell时,给每个textfield和button都绑定tag。然后,遍历整个tableview,将可见的cell中tag值与sender的tag值成一定关系的的textfield进行赋值,代码如下:
//加号键
-(void)addButton:(UIButton *)button //自定义的按钮
{
//遍历整个tableview中可见的cell
for (ShoppingCartTableViewCell *cell1 in [self.tableView visibleCells])
{
//之前在cell初始化时就将textfield的tag赋值比button大100,方便判断
if (cell1.numberTextfield.tag == button.tag+100)
{
cell1.numberTextfield.text = [NSString stringWithFormat:@"%ld",[cell1.numberTextfield.text integerValue]+1];
}
}
//之后对其他的控件进行操作
NSMutableArray *array = [[NSMutableArray alloc] init];
NSMutableArray *priceArray = [[NSMutableArray alloc]init];
for (ShoppingCartTableViewCell *cell1 in [self.tableView visibleCells])
{
goodsPrice = [NSString stringWithFormat:@"%li",[cell1.numberTextfield.text integerValue]*goodsAmount];
[array addObject: cell1.numberTextfield.text];
[priceArray addObject:goodsPrice];
}
NSNumber *sum = [array valueForKeyPath:@"@sum.floatValue"];
NSNumber *priceSum = [priceArray valueForKeyPath:@"@sum.floatValue"];
_commodityNumberLabel.text = [NSString stringWithFormat:@"共%@件商品", sum];
_totalpriceLabel.text = [NSString stringWithFormat:@"总计: %@元",priceSum];
//加号键
-(void)addButton:(UIButton *)button //自定义的按钮
{
//遍历整个tableview中可见的cell
for (ShoppingCartTableViewCell *cell1 in [self.tableView visibleCells])
{
//之前在cell初始化时就将textfield的tag赋值比button大100,方便判断
if (cell1.numberTextfield.tag == button.tag+100)
{
cell1.numberTextfield.text = [NSString stringWithFormat:@"%ld",[cell1.numberTextfield.text integerValue]+1];
}
}
//之后对其他的控件进行操作
NSMutableArray *array = [[NSMutableArray alloc] init];
NSMutableArray *priceArray = [[NSMutableArray alloc]init];
for (ShoppingCartTableViewCell *cell1 in [self.tableView visibleCells])
{
goodsPrice = [NSString stringWithFormat:@"%li",[cell1.numberTextfield.text integerValue]*goodsAmount];
[array addObject: cell1.numberTextfield.text];
[priceArray addObject:goodsPrice];
}
NSNumber *sum = [array valueForKeyPath:@"@sum.floatValue"];
NSNumber *priceSum = [priceArray valueForKeyPath:@"@sum.floatValue"];
_commodityNumberLabel.text = [NSString stringWithFormat:@"共%@件商品", sum];
_totalpriceLabel.text = [NSString stringWithFormat:@"总计: %@元",priceSum];
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询