title: How do I access objects in a UITableViewCell in a custom method?
body: <h2>Edit: This post is kinda long so the end question is copied here:</h2>
  
  <blockquote>
    <p>So obviously it is not checking the cell I am clicking, it is checking a
    new cell that it is creating.  How would I go about checking the cell
    that is clicked, and checking the content that is in that specific
    cell (i.e. checking the text of that cell's label).</p>
  </blockquote>
  
  <p>So in InterfaceBuilder I have a prototype cell, and I do the following code to create a number of cells ina  uitableview</p>
  
  <pre><code>//tableview datasource delegate methods
  -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
      return 1;
  }
  
  -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
      return cellIconNames.count;
  }
  
  -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  
  static NSString *CellIdentifier = @"Cell";
  
  cellIconName = [cellIconNames objectAtIndex:indexPath.row];
  
  
  NSString *cellIconImageName = [[self cellIconImages] objectAtIndex:[indexPath row]];
  
  CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
  
  
  if(cell == nil){
      cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  }
  cell.rightLabel.text = [cellIconNames objectAtIndex:indexPath.row];
  cell.carrierImage.image = [UIImage imageNamed:cellIconImageName];
  
  urlString = [cellButtons objectAtIndex:indexPath.row];
  
  UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  button.frame = CGRectMake(0, 0, 290, 88);
  [button setTitle:@"" forState:UIControlStateNormal];
  [button addTarget:self action:@selector(startCarrierSite:) forControlEvents:UIControlEventTouchUpInside];
  [cell.contentView addSubview:button];
  [cell.contentView bringSubviewToFront:button];
  
  return cell;
  }
  </code></pre>
  
  <p>So basically what I did is made an imageview, a label, and a seethrough button on each cell, and made the respective images and labels say different things according to an array.</p>
  
  <p>The button I have in each cell points to the same selector, startCarrierSite:</p>
  
  <p>This is the method for startCarrierSite</p>
  
  <pre><code>-(IBAction)startCarrierSite:(CustomCell *)cell;{
  
  UILabel *rightLabel = (UILabel*) [cell.subviews objectAtIndex:0];
  
  NSString *labelText = rightLabel.text;
  
  if(labelText == @"Aetna"){
      NSURL *url = [NSURL URLWithString:@"www.aetna.com"];
      [[UIApplication sharedApplication] openURL:url];
  }else{
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.google.com"]];
      }
  }
  </code></pre>
  
  <p>What I am trying to do is check the label of the cell, and if the .text of that label is equal to a certain string, I run the code for opening safari and blah blah blah, thats not the issue.</p>
  
  <p>The issue is that I can't seem to check the labels in a cell.  The current way I am trying to do this is by running the action with the argument of CustomCell (which is a child of the UITableViewCell class).</p>
  
  <p>This works and the cell is checked when you click it, but then I go to check the text of the label and it crashes.  I'm getting the error </p>
  
  <p>Terminating app due to uncaught exception 'NSRangeException', reason: '<em>*</em> -[__NSArrayI objectAtIndex:]: index 4294967295 beyond bounds for empty array'</p>
  
  <p>So obviously it is not checking the cell I am clicking, it is checking a new cell that it is creating.  How would I go about checking the cell that is clicked, and checking the content that is in that specific cell (i.e. checking the text of that cell's label).</p>
  
  <p>EDIT (ADDING IN UPDATED METHOD):</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;{
  
  CustomCell *cell = (CustomCell*)[tableView cellForRowAtIndexPath:indexPath];
  
  if ([cell.urlString isEqualToString:@"Aetna"]) {
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.aetna.com"]];
  }else if([cell.urlString isEqualToString:nil]){
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.google.com"]];
      }
  
  }
  </code></pre>