I have a main view controller(SecondViewController) with a UITable and a navigation controller. When a navigation bar button is pressed, a menu drops down from the navigation bar on top of the table. This menu is created by adding a view controller as a subview like so:
//SecondViewController.m
self = sortMenu.secondVC;
[self addChildViewController:sortMenu];
[self.view addSubview:sortMenu.view];
[sortMenu didMoveToParentViewController:self];
sortMenu contains a button that changes the order the cells are displayed in by calling a class method of the main view controller.
//SortMenuViewController.m
- (IBAction)sortButtonPressed:(id)sender {
[_secondVC sortButtonPressed:[sender tag]];
}
In sortButtonPressed, it calls a method to make a fetch request with updated sort filter value.
//SecondViewController.m
-(void)sortButtonPressed:(NSInteger)sortDescriptor{
_sortDescriptor = sortDescriptor;
currentPredicate = [NSPredicate predicateWithFormat:#"dataset & %d > 0", 4];
[self fetchResultsUsingSegmentedControlIndex];
}
The fetch request is performed and returns the data in a new order.
//SecondViewController.m
- (IBAction)fetchResultsUsingSegmentedControlIndex
{
NSString* sectionNameKeyPath = nil;
NSArray* sortDescriptors = nil;
NSSortDescriptor *scientificNameDescriptor = [[NSSortDescriptor alloc] initWithKey:#"scientificName" ascending:YES];
NSSortDescriptor *commonNameFirstDescriptor = [[NSSortDescriptor alloc] initWithKey:#"commonNameFirst" ascending:YES];
NSSortDescriptor *commonNameLastDescriptor = [[NSSortDescriptor alloc]
initWithKey:#"commonNameLast"
ascending:YES
selector:#selector(localizedCaseInsensitiveCompare:)];
if (_sortDescriptor == kSortByCommonNameFirst )
{
sortDescriptors = [[NSArray alloc] initWithObjects:commonNameFirstDescriptor, commonNameLastDescriptor, scientificNameDescriptor, nil];
sectionNameKeyPath = #"commonNameFirst";
}
else if (_sortDescriptor == kSortByCommonNameLast )
{
sortDescriptors = [[NSArray alloc] initWithObjects:commonNameLastDescriptor, commonNameFirstDescriptor, scientificNameDescriptor, nil];
sectionNameKeyPath = #"commonNameLast";
}
else if (_sortDescriptor == kSortByScientificName )
{
sortDescriptors = [[NSArray alloc] initWithObjects:scientificNameDescriptor, commonNameFirstDescriptor, commonNameLastDescriptor, nil];
sectionNameKeyPath = #"scientificName";
}
NSError *error;
NSLog(#"current predicate: %#", currentPredicate);
[[self fetchedResultsControllerWithsectionNameKeyPath:sectionNameKeyPath sortDescriptors:sortDescriptors predicate:currentPredicate] performFetch:&error];
[scientificNameDescriptor release];
[commonNameLastDescriptor release];
[commonNameFirstDescriptor release];
[sortDescriptors release];
NSUInteger sectionsCt = [[speciesFetchedResultsController sections] count];
int sum = 0;
for (int i=1; i < sectionsCt; i++){
id <NSFetchedResultsSectionInfo> sectionInfo = [[speciesFetchedResultsController sections] objectAtIndex:i];
NSUInteger numOfObj = [sectionInfo numberOfObjects];
NSLog(#" in section %d number of objects is %lu ", i, (unsigned long)numOfObj);
sum = sum + numOfObj;
}
[_table performSelectorOnMainThread:#selector(reloadData)
withObject:nil
waitUntilDone:NO];
}
When I call fetchResultsUsingSegmentedControlIndex from the main view controller (before dropping down the sort menu), it works correctly. However, when called from sortMenu, numberOfRowsInSection, numberOfSectionsInTableView, and cellForRowAtIndexPath are not called. I have tried to call reloadData on the main thread with performSelectorOnMainThread and also dispatching it to the main queue, but neither works.
I originally created a sort menu by adding a pickerview to the main view controller on pressing the navigation bar button, and my table reloaded correctly. Since creating a separate view controller for the menu (to have greater design control), it doesn't work.
Ended up using delegation.
// SortMenuViewController.h
#import <UIKit/UIKit.h>
#protocol SortMenuViewControllerDelegate <NSObject>
-(void)sortButtonPressed:(NSInteger)sortDescriptor;
-(void)viewButtonPressed:(NSInteger)viewDescriptor;
#end
#interface SortMenuViewController : UIViewController{
}
//SortMenuViewController.m
- (IBAction)changeSort:(id)sender {
[_delegate sortButtonPressed:[sender tag]];
}
//SecondViewController.h
#interface SecondViewController : UIViewController <NSFetchedResultsControllerDelegate, SortMenuViewControllerDelegate>{
}
-(void)sortButtonPressed:(NSInteger)sortDescriptor{
_sortDescriptor = sortDescriptor;
currentPredicate = [NSPredicate predicateWithFormat:#"dataset & %d > 0", dataset];
[self fetchResultsUsingSegmentedControlIndex];
}
Related
I have a simple application which is made up of a UITabBar where each Tab is a UITableViewController. For the purpose of this question, I will only focus on the UITableViewController called Videos (1st Tab) and another UITableViewController called Languages (2nd Tab).
The Videos Tab is made up of one section of a list of Videos. The Languages tab contains two sections, where section 0 is Leaflets and section 1 = the same corresponding Videos as the Videos tab.
So for example, if the Videos tab has:
Video 10010
Video 20010
Video 30010
Video 40010
Video 50010
Then the Languages tab section 1 will also have:
Video 10010
Video 20010
Video 30010
Video 40010
Video 50010
I have some code which puts a star on any cell that has been selected and the title of this cell is getting added to Core Data (to be displayed in the 3rd tab called Favourites - but this isn't important for this question).
I want to ensure consistency within the app, so if I place a star in Video 20010 in the Videos tab, I want to make sure that the Video 20010 in the Languages also has a star.
That part works. However, the issue is that the star gets placed in the Leaflets section (section 0) as well as the Videos section (section 1) of the Languages tab.
Here is part of the code of the cellForRow in the Languages tab.
// This code is important because I might set the Leaflets section to be a favourite from within the Languages tab (not related to the Videos tab, etc).
if(indexPath.section==0)
{
customCell.customCellLabel.text = [NSString stringWithFormat:#"%#",[self.availableLeaflets objectAtIndex:indexPath.row]];
NSString *key = [NSString stringWithFormat:#"%#_%ld_%ld", self.selectedLanguage, (long)indexPath.section, (long)indexPath.row];
if (self.favoritesDict[key]) {
// show the favorite image
customCell.customCellImage.hidden = NO;
} else {
// hide the favorite image
customCell.customCellImage.hidden = YES;
}
}
else
{
customCell.customCellLabel.frame = CGRectMake(8, 20, 100, 40);
customCell.customCellLabel.text = [NSString stringWithFormat:#"%#",[self.availableVideos objectAtIndex:indexPath.row]];
NSString *key = [NSString stringWithFormat:#"%#_%ld_%ld", self.selectedLanguage, (long)indexPath.section, (long)indexPath.row];
if (self.favoritesDict[key]) {
// show the favorite image
customCell.customCellImage.hidden = NO;
} else {
// hide the favorite image
customCell.customCellImage.hidden = YES;
}
}
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:#"Favourites"];
request.predicate = [NSPredicate predicateWithFormat:#"title != nil"];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:#"title" ascending:YES];
request.sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSError *error = nil;
NSArray *favs = [context executeFetchRequest:request error:&error];
if (!favs)
{
NSLog(#"Nothing to see here");
}
else
{
NSLog(#"Number of objects %lu", [favs count]);
for (Favourites *favourite in favs)
{
NSString *string = [NSString stringWithFormat:#"%#", favourite.title];
favourite.title = string;
NSLog(#"The favourite titles are %#", favourite.title);
if ([customCell.customCellLabel.text isEqualToString:favourite.title])
{
customCell.customCellImage.hidden = NO;
}
}
}
Update
When a cell is favourited, this is what's happening:
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
CustomLeafletVideoTableViewCell *selectedCell = (CustomLeafletVideoTableViewCell*)[self.tableView cellForRowAtIndexPath:indexPath];
NSString *cellTitle = selectedCell.customCellLabel.text;
NSLog(#"The text is %#", cellTitle);
NSManagedObjectContext *context = [self managedObjectContext];
NSString *key = [NSString stringWithFormat:#"%#_%ld_%ld", self.selectedLanguage, (long)indexPath.section, (long)indexPath.row];
if (self.favoritesDict[key] == nil)
{
self.favoritesDict[key] = #(1);
Favourites *favourites = [NSEntityDescription insertNewObjectForEntityForName:#"Favourites" inManagedObjectContext:context];
favourites.title = cellTitle;
}
else
{
[self.favoritesDict removeObjectForKey:key];
NSError *error;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:#"Favourites" inManagedObjectContext: context];
request.predicate = [NSPredicate predicateWithFormat:#"title == %#", cellTitle];
NSArray *items = [context executeFetchRequest:request error:&error];
if (error == nil && items.count)
{
NSManagedObject *managedObject = items[0];
[context deleteObject:managedObject];
}
}
[[NSUserDefaults standardUserDefaults] setObject:self.favoritesDict forKey:#"favoritesDict"];
NSError *error = nil;
if (![context save:&error])
{
// Error
}
[cell hideUtilityButtonsAnimated:YES];
[self.tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
I am not interested in putting the image in the Leaflets section of the Languages tab (section 0); I just want to target the Videos section (section 1). With this code above, the correct cell in section 1 is getting the UIImageView being applied, but I want to make sure the first section (Leaflets) is NOT getting the star as well.
Any guidance on this would be really appreciated.
Right after you dequeue the cell say customCell.customCellImage.hidden = YES; Then change:
if ([customCell.customCellLabel.text isEqualToString:favourite.title])
{
customCell.customCellImage.hidden = NO;
}
To:
if ([customCell.customCellLabel.text isEqualToString:favourite.title] && indexPath.section == 1)
{
customCell.customCellImage.hidden = NO;
}
In tableView:cellForRowAtIndexPath:, you have the key part, which is the indexPath. Add the following condition to your if statement.
indexPath.section == 1
I have a method in ViewController.m called getData which is called inside viewDidLoad:
-(void)getData {
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:#"WorkoutHasExercise" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
request.resultType = NSDictionaryResultType;
request.propertiesToFetch = [NSArray arrayWithObjects:#"exerciseName", #"reps", #"sets", nil];
NSPredicate *pred = [NSPredicate predicateWithFormat:#"(workoutName = %#)", _workoutName];
[request setPredicate:pred];
NSManagedObject *matches = nil;
NSError *error;
NSArray *objects = [context executeFetchRequest:request error:&error];
if ([objects count] == 0) {
} else {
[_exercises removeAllObjects];
for (int x = 0; x < [objects count]; x++) {
matches = objects[x];
[_exercises addObject:[matches valueForKey:#"exerciseName"]];
[_totalSets addObject:[matches valueForKey:#"sets"]];
[_totalReps addObject:[matches valueForKey:#"reps"]];
[_currentSets addObject:[NSNumber numberWithInteger:0]];
}
}
[_exercisesTableView reloadData];
}
I also have a custom UITableViewCell with two buttons initiated in cellForRowAtIndexPath:
ActiveWorkoutCell *cell = (ActiveWorkoutCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"ActiveWorkoutCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.increaseButton.tag = indexPath.row;
cell.decreaseButton.tag = indexPath.row;
In ActiveWorkoutCell.m I have 2 IBActions for the buttons:
- (IBAction)decreaseSets:(id)sender {
ActiveWorkoutViewController *vc = [[ActiveWorkoutViewController alloc] init];
[vc decreaseSets:[sender tag]];
}
- (IBAction)increaseSets:(id)sender {
ActiveWorkoutViewController *vc = [[ActiveWorkoutViewController alloc] init];
[vc increaseSets:[sender tag]];
}
The IBActions call these 2 methods back in ViewController.m
-(void)increaseSets:(NSInteger)row {
[self getData];
//There will be code here to increase the value of currentSets[row]
}
-(void)decreaseSets:(NSInteger)row {
[self getData]
//Code to decrease value...
}
PROBLEM:
When getData is called from viewDidLoad, it works fine.
The problem occurs when returning to ViewController.m from the IBAction in ActiveWorkoutCell.m.
When I call [self getData] in increaseSets the fetch request returns an empty array. This is what is confusing me - the code works fine when it is first called but not at all when called the second time after the custom cell Action has been triggered.
Here is my viewDidLoad if it helps:
- (void)viewDidLoad {
[super viewDidLoad];
_exercises = [NSMutableArray array];
_totalSets = [NSMutableArray array];
_currentSets = [NSMutableArray array];
_totalReps = [NSMutableArray array];
_titleLabel.text = _workoutName;
_exercisesTableView.allowsSelection = NO;
[self getData];
}
_workoutName is given a value in prepareForSegue in the previous view controller.
I think I found the issue. You are instantiating the "ActivityWorkOutViewController" when the IBAction methods called and it will be a new instance and then in those methods you are calling [self getData] which pointing to the new instance which has no variables instantiated or viewDidLoad happened, so your mutable arrays are not allocated and hence they are empty.
Just use the old instance of the class to get the data.
I am not sure how you are referencing those classes. I am just in a confusion about that. But, you might check the allocations and calling the right class to get the data
I continue to read that i should use [_context performBlock]:^... to do asynchronous searches when using core-data. What i cant figuered out for the life of me is how to subscribe to the end or the complete event sort of speak of this block. In other words in my code I'm using a UIActivityIndicatorView prior to my fetch of data and i would like to remove this view once the data has been retrieve. However I don't understand how to properly accomplish this.
In the past i have used dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{... and then implemented
dispatch_async(dispatch_get_main_queue(), ^(void) {
to know when the que is finish doing the background processing.
I might have this all completely wrong , but i figuered i ask the question. What delegate do i need to implement or what method do i need to subscribe to. To know when my fetch is complete that i have just executed within the performBlock:
Again my end goal is to set a UIActivityIndicatorView visible before the fetch , fetch the data and set it back to not visible. thanks in advance for any help you guys can offer.
**update**
I'm required to do the search asynchronously due to the large amount of records that i have to search through. I have roughly 195k records and so there is like a 1 to 2 second lag if i try to do this in the main thread when the user start to type letters in the search bar. Hence the reason why i throw up a UIActivityIndicatorView and then I do the search on the background thread and update the main thread when I'm done.
This is the code I'm using to acomplish this.
#property (strong, nonatomic) NSArray *filteredLocations;
#property (strong, nonatomic) NSArray * locationsFiltered;
//returns the search for this particular search.
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
if ([searchString length ]>= 3) {
[self searchForText:searchString];
return YES;
}
else{
self.filteredLocations = nil;
return NO;
}
//return YES;
}
- (void)searchForText:(NSString *)searchText
{
if (self.context && self.isSearching == FALSE)
{
//[searchController ]
//[self.searchDisplayController.searchResultsTableView.]
self.isSearching = TRUE;
NSString *predicateFormat = #"%K BEGINSWITH[cd] %# and state ==%#";
NSString *searchAttribute = #"name";
self.filteredLocations = nil;
NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFormat, searchAttribute, searchText,Searchstate];
[self.searchFetchRequest setPredicate:predicate];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
if (self.spinnerShowing ==FALSE) {
spinner.center = CGPointMake(160, 190);
spinner.hidesWhenStopped = YES;
spinner.color = [UIColor grayColor];
[self.view addSubview:spinner];
//self.spinnerShowing = ;
[spinner startAnimating];
}
[_context performBlock:^(void){
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSError *error = nil;
self.filteredLocations = [self.managedObjectContext executeFetchRequest:self.searchFetchRequest error:&error];
NSLog(#"this is how many items are in the filtered locations at this time %i", [_filteredLocations count]);
if (error)
{
NSLog(#"searchFetchRequest failed: %#",[error localizedDescription]);
}
dispatch_async(dispatch_get_main_queue(), ^(void) {
NSLog(#"stopping the spinner now.");
self.spinnerShowing = FALSE;
[spinner stopAnimating];
[spinner hidesWhenStopped];
self.isSearching = FALSE;
//self.searchDisplayController.searchResultsTableView.hidden = NO;
// [searchController reloadData];
[self.searchDisplayController.searchResultsTableView reloadData];
});
});
}];
}
}
It seems you have changed your question significantly after I started writing my response...
Let me know if this is of any use - otherwise I will delete as it no longer relates to your question.
Generally a second NSFetchedResultsController is, in my opinion and experience, overkill.
Note that this is written on the understanding that you have correctly implemented an instance of UISearchBar and UISearchDisplayController, either programmatically or using a Storyboard. Read a previous answer I have written that may assist if you are unsure.
As you are using a UISearchDisplayController delegate method in your question I will assume that you have declared your intended use against your #interface (i.e. <UISearchBarDelegate, UISearchDisplayDelegate>).
So finally to my answer, I prefer to implement the following code to create a reliable search method for any UITableViewController that implements an NSFetchedResultsController...
Create a public or private property (depending on your requirements) NSMutableArray to hold the contents of your search results:
#property (nonatomic, retain) NSMutableArray *searchResults;
You use this NSMutableArray to set your UITableViewController data source methods in the case that:
if (tableView == self.searchDisplayController.searchResultsTableView) {
//code for searchResultsTableView
}
Then I use UISearchDisplayController delegate methods to control any active instance of self.searchController.searchResultsTableView.
This is the most important one...
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
// Set search predicate and filter array
if (searchString && searchString.length) {
// Your predicateFormat and searchAttribute
NSString *predicateFormat = #"%K BEGINSWITH[cd] %# and state ==%#";
NSString *searchAttribute = #"name";
// My code
NSPredicate *searchPredicate = nil;
NSArray *fetchedObjects = nil;
NSMutableArray *arrayResults = nil;
[self.searchResults removeAllObjects];
searchPredicate = [NSPredicate predicateWithFormat:predicateFormat, searchAttribute, searchString, searchState];
fetchedObjects = self.fetchedResultsController.fetchedObjects;
arrayResults = [NSMutableArray arrayWithArray:[fetchedObjects filteredArrayUsingPredicate:searchPredicate]];
[self setSearchResults:arrayResults];
}
// Return YES to reload the search result table view
return YES;
}
PS- change your Searchstate variable to searchState!
You might also like to implement the following UISearchDisplayController delegate method.
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
[self setSearchResults:nil];
}
Hope this helps.
I made an application which is collecting user bills and payments. But it didn't have "Edit" property so I want to update my app with "Edit" property.
I have an tableviewcontroller which is listing user all payments. If user click the cell app goes "Detail Payment" view controller.
First of all there is my Add Payment View Controller prepare for segue codes ;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"addKredi"]) {
UINavigationController *navigationController = [segue destinationViewController];
ESMAddKrediViewController *addKrediViewController = (ESMAddKrediViewController *) navigationController.topViewController;
Kredi *addKredi = [NSEntityDescription insertNewObjectForEntityForName:#"Kredi" inManagedObjectContext:[self managedObjectContext]];
Odeme *addKrediToOdeme = [NSEntityDescription insertNewObjectForEntityForName:#"Odeme" inManagedObjectContext:[self managedObjectContext]];
addKrediViewController.addKredi = addKredi;
addKrediViewController.addKrediToOdeme = addKrediToOdeme;
}
There is the Add Credit View Controller codes;
static NSString *kategoriKredi = #"Banka Kredilerim";
_addKredi.krediAdi = _txtKrediAdi.text; //Kredi Entity
_addKrediToOdeme.odemeAdi = _txtKrediAdi.text; //Odeme Entity
_addKrediToOdeme.kategori = kategoriKredi;
My tableviewcontroller fetches user all payments via "Odeme" entity.
There is my tableviewcontroller codes to Detail ViewController ;
if user select the Credit type payment (Kredi) my app checks category with those codes and sending some info to Detail View Controller ;
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Odeme *odeme = [self.fetchedResultsController objectAtIndexPath:indexPath];
if ([odeme.kategori isEqualToString:#"Kredi Kartlarım"]){
[self performSegueWithIdentifier:#"toTaksitler" sender:nil];
}
if ([odeme.kategori isEqualToString:#"Faturalarım"]){
[self performSegueWithIdentifier:#"toFaturaDetay" sender:nil];
}
if ([odeme.kategori isEqualToString:#"Banka Kredilerim"]){
[self performSegueWithIdentifier:#"toKrediDetay" sender:nil];
}
I send odemeAdi to krediViewController.krediAdi
if ([[segue identifier] isEqualToString:#"toKrediDetay"]) {
ESMKrediViewController *krediViewController = [segue destinationViewController];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Odeme *selectedKredi = (Odeme *)[self.fetchedResultsController objectAtIndexPath:indexPath];
krediViewController.odendi = selectedKredi.odendi;
krediViewController.krediAdi = selectedKredi.odemeAdi;
krediViewController.selectedKredi = selectedKredi;
krediViewController.navigationItem.title = selectedKredi.odemeAdi;
}
I can catch the name of Credit and I fetch credit Details in my Detail ViewController with those codes ; (In CreditDetailViewController)
#pragma mark - Fetched Results Controller Section
-(NSFetchedResultsController *)fetchedResultsController{
if (_fetchedResultsController !=nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
NSManagedObjectContext *context = [self managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Kredi" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"krediAdi" ascending:YES];
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"krediAdi == %# ",krediAdi];
[fetchRequest setPredicate:predicate];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
fetchRequest.sortDescriptors = sortDescriptors;
_fetchedResultsController = [[NSFetchedResultsController alloc]initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}
And my app can show all properties about selected Credit via this way.I tried to explain all my codes.But I know its complicated question and my English is not enough to explain clearly. But maybe someone can read the codes and help this desperate guy.
So there is my question.
I want to edit Credit Detail View Controller. How can i change Kredi entity properties like krediAdi ?
I fetched all Kredi Entity properties in this detail View Controller but i can't update or override properties. I stuck there.
I solved my problem with this code ;
[[[self.fetchedResultsController fetchedObjects]objectAtIndex:0]setBorcAdi:self.txtBorcAdi.text];
BorcAdi is a Borclar entity's property.
You can edit or change the entity properties with this code.
Note:I used Predicate and i get only 1 result so i can reach it with objectAtIndex:0.
In my firstViewcontroller , I build a tableview.Its data are coming from a data base.In secondviewcontroller I insert data in the database,and I call function from firsviewcontroller to build the dictionnary data as I did in firstviewcontroller to extract data .All data are recovered from database but the tableview can't be reladed.I have no access to cellForRowAtIndexPath even numberofrowsinsection>0
This what I did :
Secondviewcontroller:
//I insert data in database and I instanciate class where my tableview is and call refresh method
first = [[FirstviewController alloc]initWithNibName:#"FirstviewController" bundle:nil];
[first refreshList];
//in Firstviewcontroller
-(void)refreshList{
self.tableview= [[[UITableView alloc] initWithFrame:self.view.bounds] autorelease];
tableview.dataSource = self;
tableview.delegate = self;
NSMutableArray *array = [[NSMutableArray alloc] init];
//I recover my data from data base
IPADAGRIONEActivityList *arrayActivities = [IPADAGRIONEActivity findAll];
if ([arrayActivities length] > 0)
{
for (IPADAGRIONEActivity * oneRec in arrayActivities)
{
[array addObject:oneRec];
}
}
//activities is NSMutablearray that contains all my data
self.activities = array;
//I build dictionnary
[self buildObjectsDictionnary:activities
NSLog(#"self.act%#",self.tableview);
[array release];
[self.tableview reloadData];
}
//numberofrowsinSection:
NSLog(#"rows%d",[[objects objectForKey:[objectsIndex objectAtIndex:section]] count]);
return [[objects objectForKey:[objectsIndex objectAtIndex:section]] ;
//numberOfSection:
NSLog(#"nbre of section%d",[objectsIndex count]);
return [objectsIndex count];}
//CellforRowatInddexPath: It dosen't access to this method
if (cell== nil) {
cell = [[MHCActivityListCell alloc]init];
}
IPADAGRIONEActivity *activite ;
cell.activityCategory.text = [NSString stringWithFormat:#"%#", [activite EMAIL]];
}
}
It looks like self.tableView is not actually visible. You re-initialize it in refreshData but you do not add it as a subview again with [self.view addSubview:self.tableView].
As I said before, IT IS INCORRECT AND BAD USAGE to re-initialize the tableView, but it looks like thats the problem.
cellForRowAtIndexPath does not get called because the tableview is not visible so it doesn't try to display cells.