Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting a predicate for different tableviews
    primarykey
    data
    text
    <p>This one has been a big problem for me, and i´m still stuck with it so i was hopping that someone could give me some kind of guidance. </p> <p><strong>What i have is:</strong></p> <ul> <li>3 tableviews with multiple cells and each cell with several textfields.</li> <li>1 tableview that appears inside a popover every time a specific textfield on those cells is pressed. This tableview has all!! the core data methods to retrieve the necessary data from my database.</li> </ul> <p>Everything works ok...but i need to distinguish what kind of data shall appear in tableview 1 or 2 or 3...So i know i have to use predicate!.</p> <p><strong>What i have done:</strong> ( and i have tried other things)</p> <pre class="lang-m prettyprint-override"><code>- (NSFetchedResultsController *)fetchedResultsController { if (_fetchedResultsController == nil) { NSFetchRequest *fetchRequestList = [[NSFetchRequest alloc] init]; NSEntityDescription *entityList = [NSEntityDescription entityForName:@"List" inManagedObjectContext:self.managedObjectContext]; [fetchRequestLista setEntity:entityList]; TableViewOne *table1 = [[Cobertura alloc]init]; TableViewTwo *table2 = [[Cobertura alloc]init]; if (table1 textFieldShouldBeginEditing:table1.textFieldPressed) { fetchRequestList.predicate = [NSPredicate predicateWithFormat:@"%K IN %@", @"reference", arrayTableview1]; } if (table2 textFieldShouldBeginEditing:table2.textFieldPressed) { fetchRequestList.predicate = [NSPredicate predicateWithFormat:@"%K IN %@", @"reference", arrayTableview2]; } NSSortDescriptor *cellTitle = [[NSSortDescriptor alloc] initWithKey:@"reference" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:cellTitle, nil]; [fetchRequestLista setSortDescriptors:sortDescriptors]; _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequestLista managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"referencia" cacheName:nil]; _fetchedResultsController.delegate = self; self.fetchedResultsController = _fetchedResultsController; return _fetchedResultsController; } </code></pre> <p>In each of my tableviews, i have an instance of the "popoverTableview" in my method textFieldShouldBeginEditing:</p> <pre class="lang-m prettyprint-override"><code>popoverTableview = [self.storyboard instantiateViewControllerWithIdentifier:@"popoverTableview"]; popover = [[UIPopoverController alloc] initWithContentViewController:popoverTableview]; [popover presentPopoverFromRect:textField.bounds inView:textField permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; popoverTableview.delegate = self; popoverTableview.popView = self.popover; </code></pre> <p>So, if i´m in tableview1 i need to get [NSPredicate predicateWithFormat:@"%K IN %@", @"reference", arrayTableview1];</p> <p>Should i be creating some kind of method that my tableviewS could access? What am i forgetting here or not paying attention?</p> <p>Thanks in advance, and any kind of advise would be welcome! Regards </p> <p><strong>For everyone that was experiencing the same problem that i was, here is what i have done to resolve:</strong></p> <p>This is when i´m creating the popoverview when a specific textfield is pressed:</p> <pre class="lang-m prettyprint-override"><code>popoverTableview = [self.storyboard instantiateViewControllerWithIdentifier:@"popoverTableview"]initWithTextFieldTag:myTextFieldThatWasPressed.tag] popover = [[UIPopoverController alloc] initWithContentViewController:popoverTableview]; [popover presentPopoverFromRect:textField.bounds inView:textField permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; popoverTableview.delegate = self; popoverTableview.popView = self.popover; popoverTableview.aIntVariable = myTextFieldThatWasPressed; </code></pre> <p>then in my popovertableview:</p> <pre class="lang-m prettyprint-override"><code>- (id)initWithTextFieldTag:(int)textFieldTag { self.aIntVariable = textFieldTag; return self; } </code></pre> <p>Then in the fetchedResultsController method, you´ll just have to create simple if´s telling wich predicate you want...</p> <p>Regards</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload