I have 2 tableViews, the first one is the Main table and the second one is the Favorites table.
Everything is handled with a plist.
From the detailView of the first table, in the upper-right corner, I created a button that writes to the plist the value YES or NO for that cell, so that that specific cell will be shown in the table Favorites.
Now the problem is that:
- I select a row from the first table, the main one. detailView appears and i tap on the UIBarButton making that detail a Favorite (and so a star image appears into the button as an image to let user know that the cell is a favorite). OK.
- I go to the second table, the favorites one, choosing the cell previously favorited and i see that the star is empty, then the bool value is set to NO (and it’s supposed to be set to YES due i Favorited it moments ago).
I noticed that if i add to favorites the first item of the firstTable, then the other cells in the second view are shown correctly, even after i favorited them all in the first view.
A bit tricky, i know, but it’s happening.
Any idea why?
The method i’m using for reading the plist is the following:
- (NSArray*)readPlist
{
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *plistPath = [[documentPaths lastObject] stringByAppendingPathComponent:@"tipsList.plist"];
NSFileManager *fMgr = [NSFileManager defaultManager];
if (![fMgr fileExistsAtPath:plistPath]) {
plistPath = [[NSBundle mainBundle] pathForResource:@"list" ofType:@"plist"];
}
NSMutableArray *returnArr = [NSMutableArray arrayWithContentsOfFile:plistPath];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"isFav == YES"];
for (NSDictionary *sect in returnArr) {
NSArray *arr = [sect objectForKey:@"Rows"];
[sect setValue:[arr filteredArrayUsingPredicate:predicate] forKey:@"Rows"];
}
return returnArr;
[self.tableView reloadData];
}
cellForRow:
- (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] autorelease];
}
NSArray *rows;
if (tableView == self.searchDisplayController.searchResultsTableView) {
rows = filteredList;
} else {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"isFav == YES"];
NSDictionary *section = [localSortedTips objectAtIndex:indexPath.section];
rows = [section objectForKey:@"Rows"];
[rows filteredArrayUsingPredicate:predicate];
}
cell.textLabel.text = [[rows objectAtIndex:indexPath.row] objectForKey:@"name"];
return cell;
}
And the didSelectRow:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ NSDictionary *section = [localList objectAtIndex:indexPath.section];
NSArray *rows = [section objectForKey:@"Rows"];
NSDictionary *item = [rows objectAtIndex:indexPath.row];
detailViewController *detail = [[detailViewController alloc] initWithNibName:@"detailViewController" bundle:nil];
detail.indexPath = indexPath;
detail.imageString = [item valueForKey:@"image"];
detail.nameString = [item valueForKey:@"name"];
detail.title = [item valueForKey:@"name"];
detail.descriptionString = [item valueForKey:@"description"];
[self.navigationController pushViewController:detail animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[detail release];
}
}
EDIT WITH PICS
Okay so. I select the first row in the first section of the mainTable, and the detailView appears:
Then i favorite it through that little star, setting its value to YES in the plist
Then I go into the Favorites table, clicking on the previously favorited element and it appears like so
OK. This works. but only for this one!
In fact, if i try to select i.e. a row in the middle of the mainTable, and try to favoriting it, the detailView looks like
But then, selecting it in the Favorites table looks like so, empty star, while it should be favorited and then filled. If i try to favorite it through the star, and coming back to the Favorites table, the previous row in the mainTable appears, even if it’s not favorited.
I noticed that if i keep the first element, it works fine, but if i remove it, it doesn’t work ANYTHING anymore. :\
Any help highly appreciated,stuck from 2 weeks.



The
indexPathyou passing to yourdetailControllerinfavoritesViewisn’t the same like the one inmainView. So you have to do some magic to parse the filteredindexPathback to the original unfiltered list.Then in
didSelectRowAtIndexPath:you pass this convertedindexPathinstead of the old one:Something I want to mention. Instead of using the
indexPathyou should use an unique identifier if possible. This would make things (like this one) much easier because you only pass thatidto the next controller.