{"id":5288,"date":"2014-03-30T20:22:09","date_gmt":"2014-03-30T20:22:09","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/objective-c-programmatically-change-table-view-from-standard-to-grouped-collection-of-common-programming-errors\/"},"modified":"2014-03-30T20:22:09","modified_gmt":"2014-03-30T20:22:09","slug":"objective-c-programmatically-change-table-view-from-standard-to-grouped-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/objective-c-programmatically-change-table-view-from-standard-to-grouped-collection-of-common-programming-errors\/","title":{"rendered":"objective-c programmatically change table view from standard to grouped?-Collection of common programming errors"},"content":{"rendered":"<p>You&#8217;ll want to use &#8220;sections&#8221; to split the table.<\/p>\n<p>First you need to sort your datasource into the desired groups, and then reflect it in the view.<\/p>\n<p>A dictionary can easily represent the grouped data. Model each group as an array that contains the entries for that group, and then add it to the dictionary with a key that represents the section.<\/p>\n<p>When the data is ungrouped, you can still use the dictionary, but with a single entry, rather than many, and then reflect that in the UI.<\/p>\n<p>That way when you&#8217;re asked how many sections there are in the table you can return <code>[dictionary count];<\/code> and then when you&#8217;re asked for the number of rows, you can do something like <code>[[dictionary objectForKey@\"myKey\"] count];<\/code><\/p>\n<p>And so on.<\/p>\n<p>When you&#8217;ve reconfigured your datasource you can call <code>[self.tableView reloadData];<\/code> to reload the table with the sections.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;ll want to use &#8220;sections&#8221; to split the table. First you need to sort your datasource into the desired groups, and then reflect it in the view. A dictionary can easily represent the grouped data. Model each group as an array that contains the entries for that group, and then add it to the dictionary [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5288","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5288"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5288\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}