Note that there are some explanatory texts on larger screens.

plurals
  1. POMove rows to bottom in a TableView which uses CoreData
    text
    copied!<p>In my app I have a folder-file (one-to-many relationship).So when I open my app, my firstViewController contains all files and when clicked on each folder, it opens a tableViewController displaying files in that folder.</p> <p>Now here whenever I swipe any row, it is moved to bottom row and the table is update accordingly, the next swiped row will go and sit above the first swiped row.</p> <p>Eg, at present if my table contains </p> <pre><code>0 1 2 3 A B C D </code></pre> <p>After swiping A</p> <pre><code>0 1 2 3 B C D **A** </code></pre> <p>after swiping B</p> <pre><code>0 1 2 3 C D **B A** </code></pre> <p>and so on, </p> <p>To do this functionality, I should update the NSOrderedSet also which is shown below</p> <pre><code>for (int i = 0; i &lt; [self.folder.file count]; i++) { File *file = [self.folder.file objectAtIndex:i]; if(file.completedStatus == false) { m_position = i; m_finalIndexPath = [NSIndexPath indexPathForRow:i inSection:0]; } } file.completedStatus = YES; id obj = [self.folder. file objectAtIndex:row]; NSMutableOrderedSet *files = [self.folder.file mutableCopy]; [files removeObjectAtIndex:row]; [files insertObject:obj atIndex:m_position]; NSIndexPath *currentIndexPath = [NSIndexPath indexPathForRow:row inSection:0]; [m_tableView moveRowAtIndexPath:currentIndexPath toIndexPath:m_finalIndexPath]; self.folder.file = files; } [self.managedObjectContext save:nil]; [m_tableView reloadData]; </code></pre> <p>This works fine in this View, and here self.folder, is particular folder on which the user clicks</p> <p>Now I have another ViewController called TestViewController where I have some of the file objects irrespective of in which ever folder they are present . I have populated the table of this TestViewController with these files, Now here also, when I swipe the cells, they will change the color but not move their position as above</p> <p>Eg </p> <pre><code>0 1 2 3 A C B D after swiping A and B 0 1 2 3 **A** C **B** D </code></pre> <p>Now here A can belong to folder 1 and B can belong to folder 2,</p> <p>when I close(dismiss) this TestViewController, What should happen is that</p> <p>a) it shows me the fileViewController by default b) the color of file A should change and it should move to a position by checking whether there are any swiped cells already. If yes, it should be placed above it or else at the bottom.</p> <p>c) similarly for color B.</p> <p>Regards Ranjit. </p>
 

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