Gajendra K Chauhan Gajendra K Chauhan - 6 months ago 13
iOS Question

Calculating value in CustomTableView

I have three fields

txtValue1
,
txtValue2
and
txtValue3
in
CustomTableCell
.

Now I want to multiply value of
txtValue1
(UITextfield) and
txtValue2
(UILabel) and display result in
txtValue3
(UILabel).

I've tried method in
cellforRowAtIndexPath
using
Double
, but it returns with empty.

How can I fix it? Thanks for any help.

//UPDATED//

Here, I am getting txtValue1 and txtValue2 from webservice. But I want to show result value in txtVale3 by calculating them. I am using customTableviewcell. e.g I want total.txt by multiplying quantity.txt and price.txt. I hope you all understand.

Answer

Add tag for UITextField say 97 and UILabel say 98 and 99 respectively in a cell.

Now use delegate method of UITextField to do multiply operation.

 - (void)textFieldDidEndEditing:(UITextField *)textField 
{
  UITableView *cell = (UITableView *)[tbView cellForRowAtIndexPath:[tbView indexPathForRowAtPoint:textField.superview.frame.origin]];
  if (cell) {
     UITextField *txtField1 = (UITextField *)(cell viewWithTag:97);
     UILabel *lbl1 = (UILabel *)(cell viewWithTag:98);
     UILabel *lbl2 = (UILabel *)(cell viewWithTag:99);

    if(txtField1)
    {
       int value1 = [txtField1.text intValue];
       int value2 = [lbl1.text intValue];
       int value3 = value1 * value2
       lbl2.text = [NSString stringWithFormat:@"%d",value3];
    }
  }    
}

EDIT : edited according to question

Comments