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 8185391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:49:56+00:00 2026-06-07T01:49:56+00:00

I am using core data to fetch an entity. I only want those results

  • 0

I am using core data to fetch an entity. I only want those results to show up in the second section of my tableview and something else show up in another section… My app isnt crashing, but the fetched data is not showing up in the table view… I also am sure I am fetching the data correctly.

Here is some code.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

if (indexPath.section==0){
    switch (indexPath.row) {
        case 0:
            cell.textLabel.text = _team.teamName;
            break;
        case 1:
            cell.textLabel.text = _team.headCoach;
            break;
        default:
            break;
    }

}

if (indexPath.section ==1) {
    Player *p = [_fetchedResultsController objectAtIndexPath: indexPath];
    cell.textLabel.text = p.firstName;
    cell.detailTextLabel.text = p.team.teamName;
}       

return cell;

}
  • 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-07T01:49:59+00:00Added an answer on June 7, 2026 at 1:49 am

    There are a couple of issues, first you should only have one section, so you don’t need to access the sections properties. So try this

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        switch(section){
            case 0:
                return 7;
            case 1:
                return [self.fetchedResultsController.fetchedObjects count];
        }
        return 0;
    }
    

    secondly, you have an issue with where you are using the following code:

    Player *p =[_fetchedResultsController objectAtIndexPath: indexPath];
    

    It is causing the problem because you are calling it for both sections and your fetch has only one section.

    To fix the crash, either wrap it with a conditional that checks for the correct indexPath.section or place it inside your switch/case statement for section 1. You can do something like this:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        }
    
        if (indexPath.section==0){
            switch (indexPath.row) {
            case 0:
                cell.textLabel.text = _team.teamName;
                break;
            case 1:
                cell.textLabel.text = _team.headCoach;
                break;
            default:
                break;
            }
    
        }else{
            Player *p = [self.fetchedResultsController.fetchedObjects objectAtIndex: indexPath.row];
            cell.textLabel.text = p.firstName;
            cell.detailTextLabel.text = p.team.teamName;
        }       
    
        return cell;
    
    }
    

    Good luck

    T

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

Sidebar

Related Questions

I am using Core Data and I only want to fetch the first record
I am using this code to fetch the core data results: -(void)getData { NSEntityDescription
Using core data I'd like to fetch some data. My model uses some abstract
I'm using the following code to fetch data out of my Core Data graph:
I am using Core Data and want a Text Label to display how many
I'm using Core Data to locally persist results from a Web Services call. The
I'm using core data and fetching the results successfully. I've few questions regarding core
I have completed and reproduced Core Data tutorials using a tableview to display contents.
I have a database of 50,000 records. I'm using core data to fetch records
I have fetching some items using CoreData and I want to filter those results

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.