UItableViewCell具有不同的UITextfields和UILabels

时间:2017-03-01 12:43:11

标签: objective-c uitableview uitableviewrowaction

我在单元格中有两个标签(总价和价格)和两个文本字段(数量和类型)。如果我更改数量文本字段,则相应的总标签应该更改。而我正在这样做。但数量功能仅针对最后一个indexpath.row,我需要在单元格中的所有行值中进行。

    UIButton *btnCancel = (UIButton *)[Cell viewWithTag:105];
    UILabel *serialNumber = (UILabel *)[Cell viewWithTag:100];
    serviceType = (IQDropDownTextField *)[Cell viewWithTag:101];
    unitPrice = (UILabel *)[Cell viewWithTag:102];
    quantity = (UITextField *)[Cell viewWithTag:103];
    total = (UILabel *)[Cell viewWithTag:104];

    [btnCancel addTarget:self action:@selector(cancelButtonPressed:) forControlEvents:UIControlEventTouchDown];

    serialNumber.text = [NSString stringWithFormat:@"%i.",(indexPath.row+1)];

    serviceType.text =[NSString stringWithFormat:@"%@",serviceArray[indexPath.row]];
    unitPrice.text = [NSString stringWithFormat:@"%@",unitArray[indexPath.row]];
    quantity.text = [NSString stringWithFormat:@"%@",quantityArray[indexPath.row]];
    price = [[unitPrice text] intValue] * [[quantity text] intValue];
    (total.text = [NSString stringWithFormat:@"%d",price]);

    [serviceType setItemList:dropDownItemArray];

    [quantity addTarget:self
                 action:@selector(textFieldDidBeginEditing:)
       forControlEvents:UIControlEventEditingChanged];

    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(150, 0, 20, 21)];
    label1.text = @"Total Amount";
    label1.font = [UIFont fontWithName:@"HelveticaNeue" size:12];
    label1.backgroundColor = [UIColor clearColor];
    label1.textColor = [UIColor colorWithRed:62/255.0f green:68/255.0f blue:75/255.0f alpha:1.0f];
    [label1 sizeToFit];
    [tableView.tableFooterView addSubview:label1];

    totalAmount = [[UILabel alloc] initWithFrame:CGRectMake(235, 0, 80, 21)];
    totalAmount.text = @"";
    totalAmount.font = [UIFont fontWithName:@"HelveticaNeue" size:12];
    totalAmount.backgroundColor = [UIColor clearColor];
    totalAmount.textColor = [UIColor colorWithRed:62/255.0f green:68/255.0f blue:75/255.0f alpha:1.0f];
    [totalAmount sizeToFit];
    [tableView.tableFooterView addSubview:totalAmount];

    int count=20;

    for(int i = 0; i <[taxType count]; i++){
        UILabel *label =  [[UILabel alloc] initWithFrame: CGRectMake(175,count,0,0)];
        UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(235,count,0,0)];
        label.text =[NSString stringWithFormat:@"%@",taxType[i]];
        label.font = [UIFont fontWithName:@"HelveticaNeue" size:12];
        label.textColor = [UIColor colorWithRed:62/255.0f green:68/255.0f blue:75/255.0f alpha:1.0f];
        [label sizeToFit];
        label1.text =[NSString stringWithFormat:@"%@",taxAmount[i]];
        label1.font = [UIFont fontWithName:@"HelveticaNeue" size:12];
        label1.textColor = [UIColor colorWithRed:62/255.0f green:68/255.0f blue:75/255.0f alpha:1.0f];
        [label1 sizeToFit];
        count+=20;
        [tableView.tableFooterView addSubview:label];
        [tableView.tableFooterView addSubview:label1];


        }

    return Cell;

}

- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return 40;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{

    price = [[unitPrice text] intValue] * [[quantity text] intValue];
            (total.text = [NSString stringWithFormat:@"%d",price]);
            (totalAmount.text =[NSString stringWithFormat:@"%d",price]);
}

0 个答案:

没有答案