title: Updating tableview cells
body: <p>I'm still really green as Object-C so hopefully I'm able to communicate this well, so hopefully with my code examples I can explain this.</p>
  
  <p>What I have is a table with four rows. Each row has a label (Clock in time, out to lunch time, etc) and a time (detailTextLabel). The label's are stored in an array and the detail's are generated from the NSDate family of functions (please forgive my terminology). In order to change the time values I use a data picker adjusted to pick time. An action is used to update the detail of a row when the time is changed using the picker.</p>
  
  <p>The follow code snippets are in the same *.m class.</p>
  
  <p>Here's a snipped down version of this -</p>
  
  <pre><code>// textLabel goes on the left, detailTextLabel goes on the right
  // This puts the labelArray on the left and times on the right
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *kCustomCellID = @"CustomCellID";
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCustomCellID];
  
      if (cell == nil)
      {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kCustomCellID] autorelease];
  
          // This disable the hightlighter effect when we select a row.
          // We need the highlighter, but we'll leave the code here.
          // cell.selectionStyle = UITableViewCellSelectionStyleNone;
      }
  
      cell.textLabel.text = [self.labelArray objectAtIndex:indexPath.row];
  
  
      // --- Start of routine to work with adding hours and minutes to stuff
  
      NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
  
      // --- Set Clock In time (initially time 'now').  
      if (indexPath.row == [labelArray indexOfObjectIdenticalTo:@"Clock In"])
      {
          self.clockIn = [NSDate date];
  
          cell.detailTextLabel.text = [self.dateFormatter stringFromDate:clockIn];
  
          NSLog(@"Clock In - %@", clockIn);
          //NSLog(@"Clock In (cell*) - %@", cell.detailTextLabel.text);
  
          return cell;
      }    
  
      // --- Set Out to Lunch time (initially clockIn + 5 hours)
      if (indexPath.row == [labelArray indexOfObjectIdenticalTo:@"Out to Lunch"])
      {
          [offsetComponents setHour:5];
  
          self.outToLunch = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]
                                dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0];
  
          cell.detailTextLabel.text = [self.dateFormatter stringFromDate:outToLunch];
  
          NSLog(@"indexPath.row (Out to Lunch): %i", indexPath.row);
  
          NSLog(@"Out to Lunch - %@", outToLunch);
          //NSLog(@"Out to Lunch (cell*) - %@", cell.detailTextLabel.text);
  
          return cell;
      }
  
      // Leaving out two other if clauses as they duplicate the Out to Lunch clause.
  
      //cell.detailTextLabel.text = [self.dateFormatter stringFromDate:[NSDate date]];
      //return cell;
      return nil;
  </code></pre>
  
  <p>This chunk of code work well and gives me no issues.</p>
  
  <p>When a row, such as "Clock In" is selected an animiation is called that scroll's up a time picking datePicker. As the times are scrolled by the "Clock In" time updates.</p>
  
  <p>Here's where I have my problem. I can't figure out how to have the "Out to Lunch" row update as the "Clock In" time is updated.</p>
  
  <p>Here's the code I have for my picking action -</p>
  
  <pre><code>- (IBAction)dateAction:(id)sender
  {
      NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
      UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
      cell.detailTextLabel.text = [self.dateFormatter stringFromDate:self.pickerView.date];
  
      NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
  
      if (indexPath.row == [labelArray indexOfObjectIdenticalTo:@"Clock In"])
      {
          if (cell.detailTextLabel.text != [self.dateFormatter stringFromDate:clockIn])
          {
              NSLog(@"clockIn time changed...");
  
              // Since clockIn time changed, we need to change outToLunch, inFromLunch, and clockOut
  
              // Change the outToLunch time
              [offsetComponents setHour:5];
  
              self.outToLunch = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]
                                 dateByAddingComponents:offsetComponents toDate:self.pickerView.date options:0];
  
              NSLog(@"New Out to Lunch time: %@", [self.dateFormatter stringFromDate:outToLunch]);
  
              // Here is where I get stuck
          }
          //return nil;
      }
  }
  </code></pre>
  
  <p>What I envision for the "Change the outToLunch time" clause is something like this...</p>
  
  <ol>
  <li>Take the new clockIn time and add 5 hours to it, and make this the new outToLunch time.
   a. NSLog just to see that this math function worked.</li>
  <li>Using the index of the detailTextLabel for the outToLunch time cell, put this new time there.</li>
  </ol>
  
  <p>There will be two more rows along with the outToLunch row that will be updated at the same time.</p>
  
  <p>How can I do this?</p>
  
  <p>Thanks for your help.</p>