title: Adding a UIView to a UITableViewCell via cell.contentView
body: <p>I have a class called GraphView that extends UIView that basically draws a small little line chart. I need one of these graphs at the top of each section in my UITableView. So I tried by creating a separate cell at the top of one of my sections and then on that cell I did:</p>
  
  <pre><code>[cell.contentView addSubview:graphView];
  [graphView release];
  </code></pre>
  
  <p>But when I scroll down, it's like the graph is glitchy and it shows up in random spots along the UITableView. Anyone have ideas or insight? Is there a better way to incorporate another UIView into the top of each section in my UITableView?</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      //NSLog(@"cellForrowAtIndexPath");
      static NSString *CellIdentifier = @"Cell";
  
      UITableViewCell *cell = [theTableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil) {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
      }
      cell.selectionStyle = UITableViewCellSelectionStyleNone;
      cell.textLabel.font = [UIFont systemFontOfSize:12];
      cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
  
  
      NSString *str1, *str2;
      if(indexPath.section == 0) {
          if(indexPath.row == 0) {
  
              str1 = @"";
              str2 = @"";
  
              S7GraphView *graphView = [[S7GraphView alloc] initWithFrame:CGRectMake(10,0,310,100)];
              graphView.dataSource = self;
  
              NSNumberFormatter *numberFormatter = [NSNumberFormatter new];
              [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
              [numberFormatter setMinimumFractionDigits:0];
              [numberFormatter setMaximumFractionDigits:0];
  
              graphView.yValuesFormatter = numberFormatter;
  
              NSDateFormatter *dateFormatter = [NSDateFormatter new];
              [dateFormatter setTimeStyle:NSDateFormatterNoStyle];
              [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  
              graphView.xValuesFormatter = dateFormatter;
  
              [dateFormatter release];        
              [numberFormatter release];
  
              graphView.backgroundColor = [UIColor whiteColor];
  
              graphView.drawAxisX = NO;
              graphView.drawAxisY = YES;
              graphView.drawGridX = NO;
              graphView.drawGridY = YES;
  
              graphView.xValuesColor = [UIColor blackColor];
              graphView.yValuesColor = [UIColor blackColor];
  
              graphView.gridXColor = [UIColor blackColor];
              graphView.gridYColor = [UIColor blackColor];
  
              graphView.drawInfo = NO;
              graphView.info = @"Load";
              graphView.infoColor = [UIColor whiteColor];
  
  
              //When you need to update the data, make this call:
  
              //[graphView reloadData];
  
              //S7GraphView *graphView = [[S7GraphView alloc] initWithFrame:CGRectMake(10,0,320,300)];
              //self.graphView.dataSource = self;
              [cell.contentView addSubview:graphView];
              [graphView release];
          }
  </code></pre>