<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Re-Ordering NSFetchedResultsController</title>
	<atom:link href="http://www.cimgf.com/2010/06/05/re-ordering-nsfetchedresultscontroller/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cimgf.com/2010/06/05/re-ordering-nsfetchedresultscontroller/</link>
	<description>Taglines are for Windows programmers</description>
	<lastBuildDate>Mon, 05 Dec 2011 10:55:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: insane-36</title>
		<link>http://www.cimgf.com/2010/06/05/re-ordering-nsfetchedresultscontroller/comment-page-1/#comment-1608</link>
		<dc:creator>insane-36</dc:creator>
		<pubDate>Tue, 17 May 2011 17:53:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.cimgf.com/?p=995#comment-1608</guid>
		<description>&lt;p&gt;I have a single entity model with some 6 attributes in it.
I have used table view to list all the datas and implemented the delegate protocols to respond to changes. I feel like I have implemented all the stuffs as it should be but the app gets stuck while deleting a row. While the app still is functional with the code the navigation around the ui element becomes impossible.
The application gets stuck at the place where the animation for the deletion of the row has just started and gets hung with the delete button and the deleting row still showing.
I get error as ,&lt;/p&gt;

&lt;p&gt;An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (8) must be equal to the number of rows contained in that section before the update (8), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) &lt;/p&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I have a single entity model with some 6 attributes in it.
I have used table view to list all the datas and implemented the delegate protocols to respond to changes. I feel like I have implemented all the stuffs as it should be but the app gets stuck while deleting a row. While the app still is functional with the code the navigation around the ui element becomes impossible.
The application gets stuck at the place where the animation for the deletion of the row has just started and gets hung with the delete button and the deleting row still showing.
I get error as ,</p>

<p>An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (8) must be equal to the number of rows contained in that section before the update (8), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) </p>]]></content:encoded>
	</item>
	<item>
		<title>By: diziet</title>
		<link>http://www.cimgf.com/2010/06/05/re-ordering-nsfetchedresultscontroller/comment-page-1/#comment-1440</link>
		<dc:creator>diziet</dc:creator>
		<pubDate>Mon, 23 Aug 2010 01:46:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.cimgf.com/?p=995#comment-1440</guid>
		<description>&lt;p&gt;I just needed to do this and was pondering a good way to do it.  Thanks for this and the other articles I&#039;ve read over the last few months!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I just needed to do this and was pondering a good way to do it.  Thanks for this and the other articles I&#8217;ve read over the last few months!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: richard</title>
		<link>http://www.cimgf.com/2010/06/05/re-ordering-nsfetchedresultscontroller/comment-page-1/#comment-1424</link>
		<dc:creator>richard</dc:creator>
		<pubDate>Mon, 16 Aug 2010 13:55:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.cimgf.com/?p=995#comment-1424</guid>
		<description>&lt;p&gt;@coopermj and @Clint. This should help...&lt;/p&gt;

&lt;p&gt;The Apple docs mention that NSFetchedResultsController is designed to respond to changes at the model level. E.g. you change the model, save it and then the view automatically updates.&lt;/p&gt;

&lt;p&gt;However when you re-order something using the tableview methods the view is already correct (because you&#039;ve dragged and dropped the cell there) and so when the delegate detects your index changes, it walks all over your view believing the cells to be in their original position. The trick is to &#039;disable&#039; the UI updates with a boolean in your delegate methods. Set the boolean just before your re-indexing and unset it afterwards.&lt;/p&gt;

&lt;p&gt;For an example, see this stack overflow link
http://stackoverflow.com/questions/1077568/how-to-implement-re-ordering-of-coredata-records&lt;/p&gt;

&lt;p&gt;For the Apple docs mention of user-driven updates, see this link
http://developer.apple.com/iphone/library/documentation/CoreData/Reference/NSFetchedResultsControllerDelegate_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40008228-CH1-SW14&lt;/p&gt;

&lt;p&gt;Hope this helps,
Richard&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@coopermj and @Clint. This should help&#8230;</p>

<p>The Apple docs mention that NSFetchedResultsController is designed to respond to changes at the model level. E.g. you change the model, save it and then the view automatically updates.</p>

<p>However when you re-order something using the tableview methods the view is already correct (because you&#8217;ve dragged and dropped the cell there) and so when the delegate detects your index changes, it walks all over your view believing the cells to be in their original position. The trick is to &#8216;disable&#8217; the UI updates with a boolean in your delegate methods. Set the boolean just before your re-indexing and unset it afterwards.</p>

<p>For an example, see this stack overflow link
<a href="http://stackoverflow.com/questions/1077568/how-to-implement-re-ordering-of-coredata-records" rel="nofollow">http://stackoverflow.com/questions/1077568/how-to-implement-re-ordering-of-coredata-records</a></p>

<p>For the Apple docs mention of user-driven updates, see this link
<a href="http://developer.apple.com/iphone/library/documentation/CoreData/Reference/NSFetchedResultsControllerDelegate_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40008228-CH1-SW14" rel="nofollow">http://developer.apple.com/iphone/library/documentation/CoreData/Reference/NSFetchedResultsControllerDelegate_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40008228-CH1-SW14</a></p>

<p>Hope this helps,
Richard</p>]]></content:encoded>
	</item>
	<item>
		<title>By: coopermj</title>
		<link>http://www.cimgf.com/2010/06/05/re-ordering-nsfetchedresultscontroller/comment-page-1/#comment-1409</link>
		<dc:creator>coopermj</dc:creator>
		<pubDate>Fri, 30 Jul 2010 17:33:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.cimgf.com/?p=995#comment-1409</guid>
		<description>&lt;p&gt;So, if I start with this and add in the code to add rows, everything blows up. Mind expanding the sample with some row adding and see if weird things happen to you? (And if not, sharing that code?)&lt;/p&gt;

&lt;p&gt;Thanks
-Micah&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>So, if I start with this and add in the code to add rows, everything blows up. Mind expanding the sample with some row adding and see if weird things happen to you? (And if not, sharing that code?)</p>

<p>Thanks
-Micah</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Long</title>
		<link>http://www.cimgf.com/2010/06/05/re-ordering-nsfetchedresultscontroller/comment-page-1/#comment-1405</link>
		<dc:creator>Matt Long</dc:creator>
		<pubDate>Wed, 21 Jul 2010 23:11:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.cimgf.com/?p=995#comment-1405</guid>
		<description>&lt;p&gt;@Clint H&lt;/p&gt;

&lt;p&gt;Thanks, Clint. I&#039;ll take a closer look when I get a chance. I can see what you&#039;re saying. It seems your solution is fine, but there may be a better way. Will see what I can find.&lt;/p&gt;

&lt;p&gt;Thanks again.&lt;/p&gt;

&lt;p&gt;-Matt&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Clint H</p>

<p>Thanks, Clint. I&#8217;ll take a closer look when I get a chance. I can see what you&#8217;re saying. It seems your solution is fine, but there may be a better way. Will see what I can find.</p>

<p>Thanks again.</p>

<p>-Matt</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Clint H</title>
		<link>http://www.cimgf.com/2010/06/05/re-ordering-nsfetchedresultscontroller/comment-page-1/#comment-1404</link>
		<dc:creator>Clint H</dc:creator>
		<pubDate>Wed, 21 Jul 2010 22:58:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.cimgf.com/?p=995#comment-1404</guid>
		<description>&lt;p&gt;Thanks Matt! I think I found a bug, however. If you re-order &lt;em&gt;more than one&lt;/em&gt; item and then re-start the app, you&#039;ll see that the ordering was &lt;em&gt;not&lt;/em&gt; persisted correctly.&lt;/p&gt;

&lt;p&gt;This seems to be caused by -tableView:moveRowAtIndexPath:toIndexPath: assuming that the array of entities returned by [fetchedResultsController fetchedObjects] is always sorted correctly--it isn&#039;t.&lt;/p&gt;

&lt;p&gt;Re-executing the fetch before (or after) your move logic does resolve the issue (here&#039;s a full example: http://pastie.org/1054504 but is it the best fix? Hopefully more experienced Core Data folk will chime in...&lt;/p&gt;

&lt;p&gt;Anyways, thanks to you and Marcus for providing such an amazing resource for everyone else--keep up the good work!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks Matt! I think I found a bug, however. If you re-order <em>more than one</em> item and then re-start the app, you&#8217;ll see that the ordering was <em>not</em> persisted correctly.</p>

<p>This seems to be caused by -tableView:moveRowAtIndexPath:toIndexPath: assuming that the array of entities returned by [fetchedResultsController fetchedObjects] is always sorted correctly&#8211;it isn&#8217;t.</p>

<p>Re-executing the fetch before (or after) your move logic does resolve the issue (here&#8217;s a full example: <a href="http://pastie.org/1054504" rel="nofollow">http://pastie.org/1054504</a> but is it the best fix? Hopefully more experienced Core Data folk will chime in&#8230;</p>

<p>Anyways, thanks to you and Marcus for providing such an amazing resource for everyone else&#8211;keep up the good work!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Taylor</title>
		<link>http://www.cimgf.com/2010/06/05/re-ordering-nsfetchedresultscontroller/comment-page-1/#comment-1362</link>
		<dc:creator>Tim Taylor</dc:creator>
		<pubDate>Sun, 06 Jun 2010 06:59:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.cimgf.com/?p=995#comment-1362</guid>
		<description>&lt;p&gt;Hi!&lt;/p&gt;

&lt;p&gt;good post.  My preference is to lazily create the fetch request and the sort descriptors.  Then when the list needs to be resorted, I will set the fetch request, sort descriptor, and then the fetchedResultsController to nil.  The getter for the sortDescriptor then is setup depending on which ever property needs to be sorted.  Then when the tableView or specific rows are reloaded the fetchedResultsController is reinitialized and the different sortDescriptor can be used.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi!</p>

<p>good post.  My preference is to lazily create the fetch request and the sort descriptors.  Then when the list needs to be resorted, I will set the fetch request, sort descriptor, and then the fetchedResultsController to nil.  The getter for the sortDescriptor then is setup depending on which ever property needs to be sorted.  Then when the tableView or specific rows are reloaded the fetchedResultsController is reinitialized and the different sortDescriptor can be used.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Cody Brimhall</title>
		<link>http://www.cimgf.com/2010/06/05/re-ordering-nsfetchedresultscontroller/comment-page-1/#comment-1360</link>
		<dc:creator>Cody Brimhall</dc:creator>
		<pubDate>Sun, 06 Jun 2010 02:53:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.cimgf.com/?p=995#comment-1360</guid>
		<description>&lt;p&gt;This is great—if only you&#039;d written it a few weeks ago! I went through a lot of trouble trying to sort a list alphabetically by a &#039;name&#039; attribute, but with with numbers last, like in the iPhone contacts app. Eventually did settle on adding a sortOrder attribute to my model, but it made me feel dirty (makes sense here, of course). Good to know that having a sortOrder attribute is basically just How It&#039;s Done.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>This is great—if only you&#8217;d written it a few weeks ago! I went through a lot of trouble trying to sort a list alphabetically by a &#8216;name&#8217; attribute, but with with numbers last, like in the iPhone contacts app. Eventually did settle on adding a sortOrder attribute to my model, but it made me feel dirty (makes sense here, of course). Good to know that having a sortOrder attribute is basically just How It&#8217;s Done.</p>]]></content:encoded>
	</item>
</channel>
</rss>

