Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:08:39+00:00 2026-06-13T02:08:39+00:00

Edit: This post is kinda long so the end question is copied here: So

  • 0

Edit: This post is kinda long so the end question is copied here:

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).

So in InterfaceBuilder I have a prototype cell, and I do the following code to create a number of cells ina uitableview

//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;
}

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.

The button I have in each cell points to the same selector, startCarrierSite:

This is the method for startCarrierSite

-(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"]];
    }
}

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.

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).

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

Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘* -[__NSArrayI objectAtIndex:]: index 4294967295 beyond bounds for empty array’

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).

EDIT (ADDING IN UPDATED METHOD):

- (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"]];
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:08:40+00:00Added an answer on June 13, 2026 at 2:08 am

    Use this UITableViewDelegate method:

    tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    

    From there you can access the cell with [tableView cellForRowAtIndexPath:indexPath]

    EDIT

    Also, do not compare strings with yourString == @"someString".

    Use [yourString isEqualToString:@"someString"].

    *EDIT 2 *

    Add a property to your CustomCell

    @property (nonatomic) NSString *urlString;

    Set the property when you are creating the cell, and then in the didSelectRowAtIndexPath method, do this;

    CustomCell *cell = (CustomCell*)[tableView cellForRowAtIndexPath:indexPath];

    Now the URL is simply cell.urlString.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
this is an edit of the original post now that I better understand the
edit This question is solved! Having something weird. I'm using html { font-size: 100%
Edit: this question is outdated. The jsonlite package flattens automatically. I am dealing with
Edit This question has gone through a few iterations by now, so feel free
EDIT: This question is a duplicate of What is the difference between managed and
I know this is probably a question that is asked a ton on here
I realize this is kind of a long question, but I saw no other
my question is, wether or not this is possible, and if so, how would
I'm kinda new to all this MVC3 stuff, and in many terms programming. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.