我在每個單元格中有一個帶有3個標籤的UITableView;活動名稱,持續時間和會見。值來自用戶輸入,存儲在活動數組中,然後顯示在表中。我不知道該怎麼做,就是將每個單元格中'met'值的值相加,並在tableView之外的另一個標籤中顯示該總和。找到每個單元格中每個標籤的總和
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellReuseIdentifier = @"CellReuseIdentifier";
TestCell *cell = [tableView dequeueReusableCellWithIdentifier:cellReuseIdentifier];
if (cell == nil) {
cell = [[TestCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellReuseIdentifier];
}
MyActivity *activity=(MyActivity *)[self.activities objectAtIndex:indexPath.row];
NSString *name = [NSString stringWithFormat:@"Activity Name: %@",activity.description];
NSString *value = [NSString stringWithFormat:@"Activity Duration: %d minutes",activity.duration];
NSString *met = [NSString stringWithFormat:@"Your MET: %d minutes",activity.duration* activity.intensity];
cell.activityLabel.text = name;
cell.durationLabel.text = value;
cell.metLabel.text = met;
return cell;
}
只是循環你的活動數組? –