Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView not showing the right cells
    primarykey
    data
    text
    <p>I have 2 tableViews, the first one is the Main table and the second one is the Favorites table.</p> <p>Everything is handled with a plist.</p> <p>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.</p> <p>Now the problem is that:</p> <ul> <li>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. </li> <li>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).</li> </ul> <p>I noticed that if i add to favorites the <strong>first</strong> item of the <strong>firstTable</strong>, then the other cells in the second view are shown correctly, even after i favorited them all in the first view.</p> <p>A bit tricky, i know, but it's happening.</p> <p>Any idea why?</p> <p>The method i'm using for reading the plist is the following:</p> <pre><code>- (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]; } </code></pre> <p>cellForRow:</p> <pre><code>- (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; } </code></pre> <p>And the didSelectRow:</p> <pre><code>- (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]; } } </code></pre> <p><strong>EDIT WITH PICS</strong></p> <p>Okay so. I select the <strong>first</strong> row in the <strong>first</strong> section of the mainTable, and the detailView appears: <a href="http://i45.tinypic.com/2lvn70x.png" rel="nofollow noreferrer">http://i45.tinypic.com/2lvn70x.png</a></p> <p>Then i favorite it through that little star, setting its value to YES in the plist</p> <p><a href="http://i45.tinypic.com/2m622a1.png" rel="nofollow noreferrer">http://i45.tinypic.com/2m622a1.png</a></p> <p>Then I go into the Favorites table, clicking on the previously favorited element and it appears like so </p> <p><a href="http://i45.tinypic.com/2m622a1.png" rel="nofollow noreferrer">http://i45.tinypic.com/2m622a1.png</a></p> <p>OK. This works. but only for <strong>this one</strong>!</p> <p>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</p> <p><a href="http://i46.tinypic.com/9vf7k5.png" rel="nofollow noreferrer">http://i46.tinypic.com/9vf7k5.png</a></p> <p>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.</p> <p><a href="http://i47.tinypic.com/2ecdidf.png" rel="nofollow noreferrer">http://i47.tinypic.com/2ecdidf.png</a></p> <p>I noticed that if i keep the first element, it works fine, but if i remove it, it doesn't work ANYTHING anymore. :\</p> <p>Any help highly appreciated,stuck from 2 weeks.</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.
 

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