title: numberOfSections being called? iOS
body: <p><strong>Skip all this info and skip to the update at the bottom...</strong></p>
  
  <p>I have dealt with unrecognized selectors before, but I cannot figure out what is going on this time. The call stack is opaque and I can't find out where the problem is originating from. I have tried using symbolic and exception breakpoints. This code was working perfectly before..I come back to work on this program some more and am now running into this</p>
  
  <pre><code>[UITableViewSectionElement numberOfSections]: unrecognized selector sent to instance 0xa285d50
  </code></pre>
  
  <p>I have two <code>UITableViews</code> in this view controller. One of them is hooked up in <code>IB(datasource and delegate)</code>. The second one is instantiated in code and its datasource/delegate are also pointing to the view controller. I put a tag of 2 on the second tableview to distinguish them from each other. <code>UITableViewTwo</code> is add to a <code>UIView</code> which is returned as the first tableview's footer if I have valid data to show. Again, this code was working perfectly without any crashes a while back, and I can't seem to figure out why it is crashing now. I am using ARC.</p>
  
  <p>Here is some code:</p>
  
  <p>When I check what the address of the object the selector being sent to is: it is indeed a <code>UITableViewSectionElement</code>. Why the H is this receiving the call numberOfSections? Isn't it supposed to be <code>numberOfSectionsInTableView</code>?</p>
  
  <pre><code>UITableView Delegate/DataSource methods
  
  -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      if (tableView.tag == 0) {
          if (indexPath.row == 0) {
              PCFCustomNumberReviewsCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"PCFNumberOfRatings"];
              [cell.numberOfReviews setText:[NSString stringWithFormat:@"%d", numReviews.integerValue]];
              [cell.numberOfReviews setFont:[PCFFontFactory droidSansFontWithSize:17]];
              [cell.numberOfReviews setTextColor:[UIColor lightGrayColor]];
              UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame];
              [imgView setImage:[UIImage imageNamed:@"1slot2.png"]];
              [cell setBackgroundView:imgView];
              return cell;
          }else if(indexPath.row == 1) {
              PCFCustomReviewCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"RateEasiness"];
              [cell.stars setBackgroundImage:[self getImageForStars:[NSString stringWithFormat:@"%d", totalEasiness.integerValue]] forState:UIControlStateNormal];
              UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame];
              [imgView setImage:[UIImage imageNamed:@"1slot2.png"]];
              [cell setBackgroundView:imgView];
              return cell;
          }else if(indexPath.row == 2) {
              PCFCustomReviewCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"RateUsefulness"];
              [cell.stars setBackgroundImage:[self getImageForStars:[NSString stringWithFormat:@"%d", totalUsefulness.integerValue]] forState:UIControlStateNormal];
              UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame];
              [imgView setImage:[UIImage imageNamed:@"1slot2.png"]];
              [cell setBackgroundView:imgView];
              return cell;
          }else if(indexPath.row == 3) {
              PCFCustomReviewCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"RateFunness"];
              [cell.stars setBackgroundImage:[self getImageForStars:[NSString stringWithFormat:@"%d", totalFunness.integerValue]] forState:UIControlStateNormal];
              UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame];
              [imgView setImage:[UIImage imageNamed:@"1slot2.png"]];
              [cell setBackgroundView:imgView];
              return cell;
          }else if(indexPath.row == 4) {
              PCFCustomReviewCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"RateInterestLevel"];
              [cell.stars setBackgroundImage:[self getImageForStars:[NSString stringWithFormat:@"%d", totalInterestLevel.integerValue]] forState:UIControlStateNormal];
              UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame];
              [imgView setImage:[UIImage imageNamed:@"1slot2.png"]];
              [cell setBackgroundView:imgView];
              return cell;
          }else if(indexPath.row == 5) {
              PCFCustomReviewCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"RateTexbookUse"];
              [cell.stars setBackgroundImage:[self getImageForStars:[NSString stringWithFormat:@"%d", totalTextbookUse.integerValue]] forState:UIControlStateNormal];
              UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame];
              [imgView setImage:[UIImage imageNamed:@"1slot2.png"]];
              [cell setBackgroundView:imgView];
              return cell;
          }else if(indexPath.row == 6) {
              PCFCustomReviewCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"RateOverall"];
              [cell.stars setBackgroundImage:[self getImageForStars:[NSString stringWithFormat:@"%d", totalOverall.integerValue]] forState:UIControlStateNormal];
              UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame];
              [imgView setImage:[UIImage imageNamed:@"1slot2.png"]];
              [cell setBackgroundView:imgView];
              return cell;
          }
  
      }else {
          PCFCustomCourseCommentCell *cell = (PCFCustomCourseCommentCell *) [self.tableViewTwo dequeueReusableCellWithIdentifier:@"PCFCourseCommentCell"];
          if (cell == nil) {
              NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"PCFCustomCourseReviewCell" owner:self options:nil];
              cell = [topLevelObjects objectAtIndex:0];
          }
          UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame];
          [imgView setImage:[UIImage imageNamed:@"1slot2.png"]];
          [cell setBackgroundView:imgView];
  
          PCFRateModel *rateObject = [courseReviews objectAtIndex:indexPath.section];
          [cell.userName setText:rateObject.username];
          [cell.date setText:rateObject.date];
          [cell.professor setText:rateObject.course];
          [cell.comment setText:rateObject.message];
          [cell.term setText:rateObject.term];
          for (UIView *view in cell.contentView.subviews) {
              if ([view isMemberOfClass:[UILabel class]]) {
                  UILabel *tempLabel = (UILabel *)view;
                  if ([tempLabel tag] != 0) {
                      [tempLabel setFont:[PCFFontFactory droidSansFontWithSize:tempLabel.tag]];
                  }
              }
          }
          CGSize size = [rateObject.message sizeWithFont:[PCFFontFactory droidSansFontWithSize:11] constrainedToSize:CGSizeMake(290, 100000)];
          [cell.comment setFrame:CGRectMake(cell.comment.frame.origin.x, cell.comment.frame.origin.y, size.width, size.height)];
          [cell.comment setBaselineAdjustment:UIBaselineAdjustmentAlignBaselines];
          [cell.comment setPreferredMaxLayoutWidth:290];
          [cell.comment setLineBreakMode:NSLineBreakByWordWrapping];
          [cell.starFunness setBackgroundImage:[self getImageForStars:rateObject.totalClarity] forState:UIControlStateNormal];
          [cell.starEasiness setBackgroundImage:[self getImageForStars:rateObject.totalEasiness] forState:UIControlStateNormal];
          [cell.starUsefulness setBackgroundImage:[self getImageForStars:rateObject.totalHelpfulness] forState:UIControlStateNormal];
          [cell.starInterestLevel setBackgroundImage:[self getImageForStars:rateObject.totalInterestLevel] forState:UIControlStateNormal];
          [cell.starOverall setBackgroundImage:[self getImageForStars:rateObject.totalOverall] forState:UIControlStateNormal];
          [cell.starTextbookUse setBackgroundImage:[self getImageForStars:rateObject.totalTextbookUse] forState:UIControlStateNormal];
          return cell;
      }
  }
  
  
  -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
      if (tableView.tag == 0) {
          if (isLoading == YES) {
              return 0;
          }else {
              return 7;
          }
      }else {
          if (isLoadingComments == NO &amp;&amp; courseReviews) {
              return 1;
          }else {
              return 0;
          }
  
      }
  }
  
  -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {
      if (isLoading == YES) return 0;
      if (tableView.tag != 0) return courseReviews.count;
      return  1;
  }
  
  -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  {
      if (section == 0 &amp;&amp; tableView.tag == 0) {
          if (isLoading == YES) {
              return  activityIndicator;
          }else if (isLoading == NO) {
              if (isLoadingComments == NO &amp;&amp; courseReviews.count &gt; 0) {
                  UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, tableViewTwo.frame.size.height)];
                  [view addSubview:tableViewTwo];
                  return view;
              }else if (isLoadingComments == YES){
                  UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
                  UIActivityIndicatorView *view = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(145, 10, 36, 36)];
                  [view setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
                  [view setColor:[UIColor whiteColor]];
                  [view startAnimating];
                  [subView addSubview:view];
                  return subView;
              }else if (!courseReviews) {
                  UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
                  UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 320, 30)];
                  [label setTextColor:[UIColor whiteColor]];
                  [label setTextAlignment:NSTextAlignmentCenter];
                  [label setFont:[PCFFontFactory droidSansFontWithSize:22]];
                  [label setText:@"No Reviews"];
                  [label setBackgroundColor:[UIColor clearColor]];
                  [view addSubview:label];
                  return view;
              }
  
          }
      }
      return nil;
  }
  -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  {
      if (tableView.tag == 0) {
          if (isLoadingComments == NO &amp;&amp; courseReviews.count &gt; 0) return tableViewTwo.frame.size.height + 50;
      }
      return 5;
  }
  -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      if (tableView.tag == 2) {
          PCFRateModel *model = [courseReviews objectAtIndex:indexPath.section];
          CGSize size = [model.message sizeWithFont:[PCFFontFactory droidSansFontWithSize:11] constrainedToSize:CGSizeMake(290, 100000)];
          return (93 + size.height + 10);
      }else {
          return tableView.rowHeight;
      }
  }
  
  -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  {
      if (section == 0 &amp;&amp; tableView.tag == 0) {
          if ([PCFInAppPurchases boughtRemoveAds] == NO) {
              if (adView &amp;&amp; adView.hidden == NO) {
                  UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)];
                  CGRect frame = adView.frame;
                  frame.origin.y = 0;
                  adView.frame = frame;
                  UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 320, 30)];
                  [label setNumberOfLines:0];
                  [label setText:classTitle];
                  [label setFont:[PCFFontFactory droidSansFontWithSize:14]];
                  [label setTextColor:[UIColor whiteColor]];
                  [label setBackgroundColor:[UIColor clearColor]];
                  [view addSubview:adView];
                  [view addSubview:label];
                  return view;
              }
          }else {
              UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 320, 30)];
              [label setNumberOfLines:0];
              [label setText:classTitle];
              [label setFont:[PCFFontFactory droidSansFontWithSize:14]];
              [label setTextColor:[UIColor whiteColor]];
              [label setBackgroundColor:[UIColor clearColor]];
              return label;
  
          }
      }
      return nil;
  }
  
  -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  {
      if (section == 0 &amp; tableView.tag == 0) {
          if ([PCFInAppPurchases boughtRemoveAds] == NO) {
              if (adView &amp;&amp; adView.hidden == NO)  {
                  return 90;
              }return 10;
          }else {
              return 30;
          }
  
      }
      return 5;
  }
  </code></pre>
  
  <p>View Did Load(The relevant information):</p>
  
  <pre><code> tableViewTwo = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, 320, self.view.bounds.size.height) style:UITableViewStyleGrouped];
      [tableViewTwo setSectionFooterHeight:0.0f];
      [tableViewTwo setDataSource:self];
      [tableViewTwo setDelegate:self];
      [tableViewTwo setTag:2];
      UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 320, 30)];
      [label setTextColor:[UIColor whiteColor]];
      [label setTextAlignment:NSTextAlignmentCenter];
      [label setFont:[PCFFontFactory droidSansFontWithSize:22]];
      [label setText:@"User Reviews"];
      [label setBackgroundColor:[UIColor clearColor]];
      [tableViewTwo setTableHeaderView:label];
      [tableViewTwo setRowHeight:136];
      [tableViewTwo setSectionFooterHeight:.01f];
      [tableViewTwo setSectionHeaderHeight:.01f];
  </code></pre>
  
  <p>I am attaching some screenshots of the app:</p>
  
  <p>Whenever I click on or try to scroll tableviewTwo I get this crash.</p>
  
  <p><img src="https://i.stack.imgur.com/TgtYV.png" alt="App Image">
  <img src="https://i.stack.imgur.com/IrVHg.png" alt="TB2">
  <img src="https://i.stack.imgur.com/zfMTk.jpg" alt="crash log 1">
  <img src="https://i.stack.imgur.com/HNhVo.jpg" alt="crash log 2">
  <img src="https://i.stack.imgur.com/yqhRz.jpg" alt="properties"></p>
  
  <p>Update:</p>
  
  <p><img src="https://i.stack.imgur.com/noXVV.png" alt="breakpoint"></p>
  
  <p>This is what it shows when I scroll the second <code>UITableView</code>(with all exceptions enabled):</p>
  
  <p><img src="https://i.stack.imgur.com/hJIV0.jpg" alt="first line shown">
  <img src="https://i.stack.imgur.com/SKjyz.jpg" alt="after clicking continue"></p>
  
  <p>I have a build of this working perfectly on my phone(a month ago)..I don't know why I am getting this error now. Could a change if Interface Builder have caused this? I have checked all the outlets and included them. Thanks..</p>
  
  <p>Update:</p>
  
  <p>Oddly enough, when I clone the repo on another laptop it is working without problems. I think somehow the project I was using was corrupted? I will go home and investigate further. </p>
  
  <p>Any ideas as to why this is not crashing on my work laptop(similiar specs) and is crashing on my laptop. I have cloned the git directory in both laptops and I am getting a crash here, but not there. I am running XCode version 4.6.3 on my laptop.</p>
  
  <p>Update 2:</p>
  
  <p>It is no longer working on my work laptop..WTF is going on? Is there a bug in Xcode 4.6.3? Is there anything I can do to troubleshoot this further? Why is numberOfSections being called? I can't find documentation on that online ANYWHERE.</p>
  
  <p>Update 3:</p>
  
  <p>Okay, it turns out that this line of code in the viewForFooterInSection selector is the culprit:</p>
  
  <pre><code>UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, tableViewTwo.frame.size.height)];
                  [view addSubview:tableViewTwo];
                  return view;
  </code></pre>
  
  <p>It works fine on the device but crashes on the simulator. When I simply change it to the following..it works.</p>
  
  <pre><code>return tableViewTwo;
  </code></pre>
  
  <p>Does anyone know why the returning the tableview in a view is giving an error?</p>