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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:38:05+00:00 2026-05-25T12:38:05+00:00

I have two entity with a many-to-one relationship. For example Employee <<—> Shop .

  • 0

I have two entity with a many-to-one relationship. For example Employee <<---> Shop. When I create a new employee, I can choose a shop for it. I fetch all the available shops and then I select one from the table view.
Now, I want to add a new row in this table to be able to set nil to the relationship, for example by adding a row called "None" and when it’s selected, the relationship will be employee.shop = nil;
Is it possible? I don’w know how to configure the table view to do this job…
However, this is the code used to fetch the shops:

-(NSArray *)projectsList
{
    if (!projectsList) {
        NSFetchRequest *request = [[NSFetchRequest alloc] init];
        NSEntityDescription *entity = [NSEntityDescription entityForName:@"Project" inManagedObjectContext:taskObject.managedObjectContext];
        [request setEntity:entity];

        NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES];
        NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
        [request setSortDescriptors:sortDescriptors];

        NSError *error = nil;
        NSArray *projects = [taskObject.managedObjectContext executeFetchRequest:request error:&error];
        if (!projects) {
            NSLog(@"Risultati della richiesta nulli!");
            abort();
        }

        projectsList = [projects mutableCopy];
    }

    return projectsList;
}

and some tableView methods:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[self projectsList] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

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

    Project *project = (Project *)[[self projectsList] objectAtIndex:indexPath.row];
    cell.textLabel.text = project.title;

    if (project == taskObject.project) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    Project *project = (Project *)[projectsList objectAtIndex:indexPath.row];
    taskObject.project = project;

    NSError *error = nil;
    if (![taskObject.managedObjectContext save:&error]) {
        NSLog(@"Errore nel salvare il progetto per il task! %@, %@", error, [error userInfo]);
        abort();
    }
    else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

Thank you so much!

  • 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-05-25T12:38:06+00:00Added an answer on May 25, 2026 at 12:38 pm

    This should do it.

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [[self projectsList] count] + 1;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
    
        if ( indexPath.row == [projectsList count] )
        {
            cell.textLabel.text = @"None";
            cell.accessoryType = ( taskObject.project ) ? UITableViewCellAccessoryNone : UITableViewCellAccessoryCheckmark;
        }
        else
        {
            Project *project = (Project *)[[self projectsList] objectAtIndex:indexPath.row];
            cell.textLabel.text = project.title;
    
            if (project == taskObject.project) {
                cell.accessoryType = UITableViewCellAccessoryCheckmark;
            }
            else {
                cell.accessoryType = UITableViewCellAccessoryNone;
            }
        }
    
        return cell;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    
        if ( indexPath.row == [projectsList count] )
        {
            taskObject.project = nil;
        }
        else
        {
            Project *project = (Project *)[projectsList objectAtIndex:indexPath.row];
            taskObject.project = project;
        }
    
        NSError *error = nil;
        if (![taskObject.managedObjectContext save:&error]) {
            NSLog(@"Errore nel salvare il progetto per il task! %@, %@", error, [error userInfo]);
            abort();
        }
        else {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a one to many entity relationship between two entities: EntityP (Parent) <-->>
Suppose i have a one to many relationship between two model entities Entity One
I have a Department entity which has a one-to-many relationship to an Employee entity.
I have two Entity Framework objects with a one-to-many relationship: widget(parent) and widgetNail(child) Widget
I have a fairly simple Many to One relationship between two classes: @Entity public
I have two entities, Entity1 and Entity2, on a one to many relationship. On
This is situation I have: I have two entities with one-to-many relationship mapped like
i have two entities named Parent and Child , linked in a one-to-many relationship.
I have two entities, Job and Language , in a many-to-one relationship. The mapping
I have two classes university and department, suppose there is one to many relationship

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.