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

  • SEARCH
  • Home
  • 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 9094033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:15:06+00:00 2026-06-16T23:15:06+00:00

I have populated a NSArray with results of a query from MagicalRecord (a Core

  • 0

I have populated a NSArray with results of a query from MagicalRecord (a Core Data wrapper). I need to take those results and display them in custom cells in a UITableView from within cellForRowAtIndexPath:, but the index refers to another UITableView that has been selected.

I have two UITableViews; one contains a list of customers, the other contains a list of appointments for each customer. When the user selects a customer, the code finds all of the appointments for that customer. As such, there is no index involved with the second table view).

The first table view has a list of clients; when the user selects one of those clients, the second table view is populated with a list of appointments for that selected client. Thus the index.row refers to the first UITableView and the second has no index it can refer to. I just dump the contents of the apptDataArrray into the cells.

Here is my code:

if(tableView.tag == 2) {  //  appointment info  
    static NSString *cellIdentifier = @"apptListCell";
    ApptCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if(cell == nil)  {
        cell = [[ApptCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    //  configure the cell...
    AppointmentInfo *currentAppointment = [apptDataArray objectAtIndex: 0];  //  go through the array  <---- TODO

    // Set the dateFormatter format
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];  //  start date/time
    [timeFormatter setDateFormat:@"HH:mm:ss"];  //  end time

    UILabel *label = (UILabel *)[cell viewWithTag:3];  //  display start date/time  (NEEDS TO BE LOCALIZED!)<-----  TODO????
    label.text = [dateFormatter stringFromDate:currentAppointment.aStartTime];

    label = (UILabel *)[cell viewWithTag:4];  //  display end time
    label.text = [timeFormatter stringFromDate:currentAppointment.aEndTime];

    label = (UILabel *)[cell viewWithTag:5];  //  display service tech name
    label.text = currentAppointment.aServiceTech;

    return cell;

}

My question is: When at the line below // configure the cell, how do I iterate through the apptDataArray each time cellForRowAtIndexPath: is called, since there is NO index that can be applied to this array?

  • 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-16T23:15:07+00:00Added an answer on June 16, 2026 at 11:15 pm

    from within cellForRowAtIndexPath: but the index refers to another UITableView that has been selected.

    What?! No, it doesn’t. You have a serious misunderstanding. The full name of that method is tableView:cellForRowAtIndexPath:. Any table view that needs to display a cell passes itself as the first argument, and it passes the index path for its own single cell* as the second. When the second table view is asking your data source for its cell information — when your test tableView.tag == 2 test is true — the passed-in index path refers to that table. How could it possibly work otherwise?

    All you need to do is

    AppointmentInfo *currentAppointment = [apptDataArray objectAtIndex: indexPath.row];
    

    the same as you would for any other array-backed table view.

    There’s no magic going on here. You’ve given the table view a pointer to your object and told the table to get information it needs from that object. The table then sends messages, just like anything else, to the data source object. One of those messages is tableView:cellForRowAtIndexPath:. The fact that another table view also sends that message sometimes doesn’t affect the first. Each table view will interact with your data source only on its own behalf.

    As a note, this problem — even the description of your app’s structure — indicates strongly that you should probably have a separate data source/delegate object for each of your table views.


    *Somewhere in the comments you seemed to imply that you think you need to set up all the cells in the table view during one call of tableView:cellForRowAtIndexPath:, and that’s not right either. You need to configure and return just the one single cell that corresponds to the index path.

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

Sidebar

Related Questions

In my app, I have a UITableView that is populated by Core Data, currently
I have an NSArray which is populated with objects from an NSMutableArray. Most of
I have a tableview where each cell is populated with dynamic data from an
I have a uitableview with 50 rows populated from a predefined nsarray. How can
I have an interesting trouble: I have a NSArray which is populated with some
I have implemented the search method for a UITableView populate from a NSArray (mylist):
I have a UITableView populated by a feed from searchtwitter.com. I also have a
I have a core data entity called TruckNumber which has a string as it's
I have an NSArray of CalEvents returned with the [CalCalendarStore eventPredicateWithStartDate] method. From the
I am creating an app which uses Core Data. I have a flip-side in

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.