0

I have a custom tableViewCell in which one label present in each cells

so I have to calculate labels value and show the total in other label which is present in the same view

please any one suggest me what I do?"

1
  • what do you mean by labels value? Commented Jun 10, 2016 at 6:08

3 Answers 3

0

You can take one global float or double variable. In cellforrowatindexpath delegate method,you can do any mathematical operation and display global variable value in second label.

Regards...

-Harsh Shah

Sign up to request clarification or add additional context in comments.

Comments

0

You must have been setting your label values from some array or dictionary. Then just get the values from your array/ dictionary and add them then in

tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell?

Compare current indexPath.row with your needed indexPath.row which may be at the last(i.e, your array count) , and there set the label value accordingly.

Comments

0

First of all, you can't get all cells without scrolling them. You can only get first visible cells. So my suggestion is that get the total row count from the response and get the values from each label and add their value and show the total in another label.

For example:

NSMutableArray *responseArray=[[NSMutableArray alloc]initWithObjects:@"2",@"4",@"6",nil];
int count = 0;
for(int i=0;i<[responseArray count];i++)
{
    count=count+[[responseArray objectAtIndex:i] intValue];
}

UILabel *lblTotalCount=[UILabel new];
lblTotalCount.text=[NSString stringWithFormat:@"%d",count];

NSLog(@"lblTotalCount.text-->%@",lblTotalCount.text);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.