{"title":"Create Static Content Screens with Ease!","html_url":"https://deallocatedobjects.com/posts/create-static-content-screens-with-jmstaticcontenttableviewcontroller","source_url":"http://bitly.com/OGCvCY","markdown_content":"I often find myself needing to create what I call \"static content\" `UITableViewControllers`. Whether it be a \"Support\" or \"About\" screen, or possibly a simple \"Login\" or \"Settings\" screen, I find myself writing a ton of annoying, repetitive, boilerplate code for these types of screens all the time.\r\n\r\nWhat's a guy to do? Enter: [`JMStaticContentTableViewController`](http://bitly.com/OGCvCY).\r\n\r\n[Check it out on Github here](http://bitly.com/OGCvCY).\r\n\r\n### What Exactly Is It?\r\n\r\nA `UITableViewController` subclass that allows you easily and simply display what I call \"static content\". An example of such content is what is found in iOS's built-in Settings application. Or a  simple \"About\" screen. Or a \"Login\" screen. Or any number of simple screens that might display or collect information.\r\n\r\nAll this is done using some really cool methods that use blocks. It also allows you to easily create `UITableViewControllers` that collection information.\r\n\r\nIt is very much a library in the making. It is quite functional and usable already, as you will see if you read on, however, there is a TON more that *could* be done with this library, I'd love to hear where everyone thinks it should go and how it could best be adapted to fit everyone's needs.\r\n\r\nThat being said, `JMStaticContentTableViewController` might not be for everyone, but if you've ever built a whole `UITableViewController` implementing full `UITableViewDataSource` and `UITableViewDelegate` methods, and so on, and so on, then you likely know how much time this library could save you. \r\n\r\nKeep reading for some awesome stuff.\r\n\r\n### Example Usage\r\n\r\n#### Adding a section and a cell\r\n\r\nHere's a simple example of adding a section and a cell to your `UITableView`. You would likely write this code inside your `viewDidLoad` method inside your `JMStaticContentTableViewController` subclass.\r\n\r\nNote that you are passed in some very important objects, `JMStaticContentTableViewSection`, `JMStaticContentTableViewCell` and a `UITableViewCell`. You can configure the `UITableViewCell` exactly as you would normally. We also use the `JMStaticContentTableViewCell` object to setup things like `UITableViewCellStyle` and the reuse identifier.\r\n\r\n`JMStaticContentTableViewSection` also allows you to setup things like the section titles.\r\n\r\nAs you can see we also get a nice looking `whenSelected:` block, this allows to write code that will be run whenever our cell is tapped, a perfect place to, for example, push on a `UIViewController`.\r\n\r\n``` objective-c\r\n- (void) viewDidLoad {\r\n\t[super viewDidLoad];\r\n\r\n\t[self addSection:^(JMStaticContentTableViewSection *section, NSUInteger sectionIndex) {\r\n\t\t[section addCell:^(JMStaticContentTableViewCell *staticContentCell, UITableViewCell *cell, NSIndexPath *indexPath) {\r\n\t\t\tstaticContentCell.cellStyle = UITableViewCellStyleValue1;\r\n\t\t\tstaticContentCell.reuseIdentifier = @\"DetailTextCell\";\r\n\r\n\t\t\tcell.textLabel.text = NSLocalizedString(@\"Wi-Fi\", @\"Wi-Fi\");\r\n\t\t\tcell.detailTextLabel.text = NSLocalizedString(@\"T.A.R.D.I.S.\", @\"T.A.R.D.I.S.\");\r\n\t\t} whenSelected:^(NSIndexPath *indexPath) {\r\n\t\t\t[self.navigationController pushViewController:[[WifiViewController alloc] init] animated:YES];\r\n\t\t}];\r\n\t}];\r\n}\r\n```\r\n\r\n#### Inserting A Cell At Runtime\r\n\r\nThis will behave just like `addCell:` above, except it will animate nicely into place.\r\n\r\n``` objective-c\r\n- (void) _someTaskFinished {\r\n\t[self insertCell:^(JMStaticContentTableViewCell *staticContentCell, UITableViewCell *cell, NSIndexPath *indexPath) {\r\n\t\tstaticContentCell.reuseIdentifier = @\"WifiNetworkCell\";\r\n\t\tstaticContentCell.tableViewCellSubclass = [WifiNetworkTableViewCell class];\r\n\r\n\t\tcell.textLabel.text = network.networkName;\r\n\t\tcell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;\r\n\t\t\r\n\t\tcell.indentationLevel = 2;\r\n\t\tcell.indentationWidth = 10.0;\r\n\t} whenSelected:^(NSIndexPath *indexPath) {\r\n\t\t// TODO\r\n\t} atIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES];\r\n}\r\n\r\n```\r\n\r\n#### Inserting Multiple Cells At Runtime\r\n\r\nSame as above, except here we're wrapping our work in calls to `beginUpdates` and `endUpdates`, again retaining all of our `UITableView`'s built in \"magic\" while still getting to use our nice, convenient syntax.\r\n\r\n``` objective-c\r\n// Somewhere else you'd probably load some data somehow,\r\n// then want to insert rows for the new items in that data.\r\n\r\n// Normal table view functionality is completely retained, for example,\r\n// here we're inserting a bunch of cells inside a beginUpdates/endUpdates block\r\n// so all our new cells will animate in simultaneously and look awesome.\r\n\r\n[self.tableView beginUpdates];\r\n\r\nfor(SomeModelObject *o in self.awesomeModelObjects) {\r\n\t[self insertCell:^(JMStaticContentTableViewCell *staticContentCell, UITableViewCell *cell, NSIndexPath *indexPath) {\r\n\t\tstaticContentCell.reuseIdentifier = @\"SomeCell\";\r\n\t\r\n\t\tcell.textLabel.text\r\n\t} atIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES];\r\n}\r\n\r\n[self.tableView endUpdates];\r\n\t\r\n```\r\n#### Animation\r\n\r\nAnytime you ask `JMStaticContentTableViewController` to animate the inserting or deleting of cells or sections, it will use the `UITableViewRowAnimation` style of `UITableViewRowAnimationAutomatic` under the hood, so all of your animations will look great. This style was added in iOS 5.\r\n\r\n### Example App\r\n\r\nSo for fun (and to aid me in developing the library, determine its needs) I started using `JMStaticTableViewController` to attempt to re-create the built-in iOS Settings application. This exists in a sort of \"half-finished\" state inside [the library's Github repo](http://bitly.com/OGCvCY)\r\n\r\nSome things to try in it are: \r\n\r\n* Wi-Fi, go into the Wi-Fi section and notice how the rows appear after \"searching for networks\" (this is obviously simulated). Also try disabling and re-enabling Wi-Fi. Notice how the rows appear and disappear with correct animations. \r\n\r\n* The Notifications section also demonstrates showing some content.\r\n\r\n* Cells that shouldn't be \"selectable\" (like cells containing `UISwitch` controls) aren't selectable.\r\n\r\n* Normal `UITableViewDelegate` methods still work, so implementing things like like adding a `UIActivityIndicatorView` next to a section title are no more or less complicated than before.\r\n\r\nIt is, like I mentioned, unfinished, meant merely as a tool for you to checkout and get some perspective on how the library might be used in the \"real world\". More completion of the example as well as any other examples are very welcome, please feel free to submit pull requests.\r\n\r\n#### Example App Screenshots\r\n\r\n<div style=\"width: 84%; margin: 10px auto;\">\r\n<img src=\"http://cl.ly/IKD6/iOS%20Simulator%20Screen%20shot%20Jul%2025,%202012%207.08.00%20PM.png\" width=\"42%\" style=\"float: left; margin-right: 10px;\" />&nbsp;&nbsp;\r\n<img src=\"http://cl.ly/IKjt/iOS%20Simulator%20Screen%20shot%20Jul%2025,%202012%207.08.01%20PM.png\" width=\"42%\" style=\"float: left; margin-bottom: 10px;\" />&nbsp;&nbsp;\r\n<img src=\"http://cl.ly/IKkO/iOS%20Simulator%20Screen%20shot%20Jul%2025,%202012%207.08.02%20PM.png\" width=\"42%\" style=\"float: left; margin-right: 10px;\" />&nbsp;&nbsp;\r\n<img src=\"http://cl.ly/IKcB/iOS%20Simulator%20Screen%20shot%20Jul%2025,%202012%207.08.04%20PM.png\" width=\"42%\" style=\"float: left; margin-bottom: 10px;\" />&nbsp;&nbsp;\r\n<img src=\"http://cl.ly/IKMS/iOS%20Simulator%20Screen%20shot%20Jul%2025,%202012%207.08.07%20PM.png\" width=\"42%\" style=\"float: left; margin-bottom: 20px;\" />\r\n</div>\r\n\r\n<div style=\"clear: both;\"></div>\r\n\r\n### iOS Version Compatability\r\n\r\n`JMStaticContentTableViewController` supports iOS 5 and up.\r\n\r\n### Adding To Your Project\r\n\r\n#### CocoaPods (The New Easy Way)\r\n\r\nIf you are using [CocoaPods](http://cocoapods.org) then just add this line to your `Podfile`:\r\n\r\n``` ruby\r\ndependency 'JMStaticContentTableViewController'\r\n```\r\n\r\nNow run `pod install` to install the dependency.\r\n\r\n#### Manually (The Old Hard Way)\r\n\r\n[Download](https://github.com/jakemarsh/JMStaticContentTableViewController/zipball/master) the source files or add it as a [git submodule](http://schacon.github.com/git/user-manual.html#submodules). Here's how to add it as a submodule:\r\n\r\n    $ cd YourProject\r\n    $ git submodule add https://github.com/jakemarsh/JMStaticContentTableViewController.git Vendor/JMStaticContentTableViewController\r\n\r\nAdd all of the files inside the folder named \"JMStaticContentTableViewController\" to your project.\r\n\r\n#### ARC\r\n\r\n`JMStaticContentTableViewController` uses [Automatic Reference Counting (ARC)](http://clang.llvm.org/docs/AutomaticReferenceCounting.html). You should be using ARC too, it's the future. If your project doesn't use ARC, you will need to set the `-fobjc-arc compiler` flag on all of the `JMStaticContentTableViewController` source files. To do this in Xcode, go to your active target and select the \"Build Phases\" tab. In the \"Compiler Flags\" column, set `-fobjc-arc` for each of the `JMStaticContentTableViewController` source files.\r\n\r\n#### \"This Library is Bad, and You Should Feel Bad\"\r\n\r\n<center><img src=\"http://cdn.memegenerator.net/instances/400x/23854749.jpg\" title=\"This Library is Bad, and You Should Feel Bad\" /></center>\r\n\r\nThis is my first try at building a system like this for this purpose, there are already a ton of things I plan on \"fixing\", improving, and re-doing. I wouldn't really be a good developer if I didn't hate all my code once I was done would ? ;)\r\n\r\nI'm totally open to suggestions/fixes/hate mail/etc just let me know in a pull request, issue or even on twitter, I'm [@jakemarsh](http://twitter.com/jakemarsh).\r\n\r\nThat being said, this is a very opinionated library. It makes assumptions and defines conventions that might not fit perfectly with everyone's codebase or app. If you are one of those people, please feel free to submit a pull request so we can talk about it and maybe get some of your desired changes worked in.\r\n\r\n[Check it out on Github here](http://bitly.com/OGCvCY).","html_content":"<p>I often find myself needing to create what I call “static content” <code>UITableViewControllers</code>. Whether it be a “Support” or “About” screen, or possibly a simple “Login” or “Settings” screen, I find myself writing a ton of annoying, repetitive, boilerplate code for these types of screens all the time.</p>\n\n<p>What’s a guy to do? Enter: <a href=\"http://bitly.com/OGCvCY\"><code>JMStaticContentTableViewController</code></a>.</p>\n\n<p><a href=\"http://bitly.com/OGCvCY\">Check it out on Github here</a>.</p>\n\n<h2 id=\"what-exactly-is-it\" data-level=\"3\">What Exactly Is It?</h2>\n\n<p>A <code>UITableViewController</code> subclass that allows you easily and simply display what I call “static content”. An example of such content is what is found in iOS’s built-in Settings application. Or a  simple “About” screen. Or a “Login” screen. Or any number of simple screens that might display or collect information.</p>\n\n<p>All this is done using some really cool methods that use blocks. It also allows you to easily create <code>UITableViewControllers</code> that collection information.</p>\n\n<p>It is very much a library in the making. It is quite functional and usable already, as you will see if you read on, however, there is a TON more that <em>could</em> be done with this library, I’d love to hear where everyone thinks it should go and how it could best be adapted to fit everyone’s needs.</p>\n\n<p>That being said, <code>JMStaticContentTableViewController</code> might not be for everyone, but if you’ve ever built a whole <code>UITableViewController</code> implementing full <code>UITableViewDataSource</code> and <code>UITableViewDelegate</code> methods, and so on, and so on, then you likely know how much time this library could save you. </p>\n\n<p>Keep reading for some awesome stuff.</p>\n\n<h2 id=\"example-usage\" data-level=\"3\">Example Usage</h2>\n\n<h3 id=\"adding-a-section-and-a-cell\" data-level=\"4\">Adding a section and a cell</h3>\n\n<p>Here’s a simple example of adding a section and a cell to your <code>UITableView</code>. You would likely write this code inside your <code>viewDidLoad</code> method inside your <code>JMStaticContentTableViewController</code> subclass.</p>\n\n<p>Note that you are passed in some very important objects, <code>JMStaticContentTableViewSection</code>, <code>JMStaticContentTableViewCell</code> and a <code>UITableViewCell</code>. You can configure the <code>UITableViewCell</code> exactly as you would normally. We also use the <code>JMStaticContentTableViewCell</code> object to setup things like <code>UITableViewCellStyle</code> and the reuse identifier.</p>\n\n<p><code>JMStaticContentTableViewSection</code> also allows you to setup things like the section titles.</p>\n\n<p>As you can see we also get a nice looking <code>whenSelected:</code> block, this allows to write code that will be run whenever our cell is tapped, a perfect place to, for example, push on a <code>UIViewController</code>.</p>\n<figure class=\"code\" data-lang=\"objective-c\"><figcaption><span class=\"lang\">Objective-C</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">-</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> (</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">void</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) viewDidLoad {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    [</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">super</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> viewDidLoad</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">];</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    [</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">self</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> addSection:</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">^</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(JMStaticContentTableViewSection </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">*</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">section, </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">NSUInteger</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> sectionIndex) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">        [section </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">addCell:</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">^</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(JMStaticContentTableViewCell </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">*</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">staticContentCell, UITableViewCell </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">*</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">cell, </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">NSIndexPath</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> *</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">indexPath) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">            staticContentCell.cellStyle </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> UITableViewCellStyleValue1;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">            staticContentCell.reuseIdentifier </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> @\"DetailTextCell\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">            cell.textLabel.text </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> NSLocalizedString</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">@\"Wi-Fi\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">@\"Wi-Fi\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">            cell.detailTextLabel.text </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> NSLocalizedString</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">@\"T.A.R.D.I.S.\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">@\"T.A.R.D.I.S.\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">        } </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">whenSelected:</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">^</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">NSIndexPath</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> *</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">indexPath) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">            [</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">self</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.navigationController </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">pushViewController:</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">[[WifiViewController </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">alloc</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">] </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">init</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">] </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">animated:YES</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">];</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">        }];</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    }];</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">}</span></span></code></pre></figure>\n<h3 id=\"inserting-a-cell-at-runtime\" data-level=\"4\">Inserting A Cell At Runtime</h3>\n\n<p>This will behave just like <code>addCell:</code> above, except it will animate nicely into place.</p>\n<figure class=\"code\" data-lang=\"objective-c\"><figcaption><span class=\"lang\">Objective-C</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">-</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> (</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">void</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) _someTaskFinished {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    [</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">self</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> insertCell:</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">^</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(JMStaticContentTableViewCell </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">*</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">staticContentCell, UITableViewCell </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">*</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">cell, </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">NSIndexPath</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> *</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">indexPath) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">        staticContentCell.reuseIdentifier </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> @\"WifiNetworkCell\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">        staticContentCell.tableViewCellSubclass </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> [WifiNetworkTableViewCell </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">class</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">];</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">        cell.textLabel.text </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> network.networkName;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">        cell.accessoryType </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> UITableViewCellAccessoryDetailDisclosureButton;</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">        cell.indentationLevel </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 2</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">        cell.indentationWidth </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 10.0</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    } </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">whenSelected:</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">^</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">NSIndexPath</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> *</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">indexPath) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">        // TODO</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    } </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">atIndexPath:</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">[</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">NSIndexPath</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> indexPathForRow:0</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> inSection:0</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">] </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">animated:YES</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">];</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">}</span></span></code></pre></figure>\n<h3 id=\"inserting-multiple-cells-at-runtime\" data-level=\"4\">Inserting Multiple Cells At Runtime</h3>\n\n<p>Same as above, except here we’re wrapping our work in calls to <code>beginUpdates</code> and <code>endUpdates</code>, again retaining all of our <code>UITableView</code>‘s built in “magic” while still getting to use our nice, convenient syntax.</p>\n<figure class=\"code\" data-lang=\"objective-c\"><figcaption><span class=\"lang\">Objective-C</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">// Somewhere else you'd probably load some data somehow,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">// then want to insert rows for the new items in that data.</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">// Normal table view functionality is completely retained, for example,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">// here we're inserting a bunch of cells inside a beginUpdates/endUpdates block</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">// so all our new cells will animate in simultaneously and look awesome.</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">[</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">self</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.tableView </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">beginUpdates</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">];</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">for</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(SomeModelObject </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">*</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">o </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">in</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> self</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.awesomeModelObjects) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    [</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">self</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> insertCell:</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">^</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(JMStaticContentTableViewCell </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">*</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">staticContentCell, UITableViewCell </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">*</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">cell, </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">NSIndexPath</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> *</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">indexPath) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">        staticContentCell.reuseIdentifier </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> @\"SomeCell\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">        cell.textLabel.text</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    } </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">atIndexPath:</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">[</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">NSIndexPath</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> indexPathForRow:0</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> inSection:0</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">] </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">animated:YES</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">];</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">}</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">[</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">self</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.tableView </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">endUpdates</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">];</span></span></code></pre></figure>\n<h3 id=\"animation\" data-level=\"4\">Animation</h3>\n\n<p>Anytime you ask <code>JMStaticContentTableViewController</code> to animate the inserting or deleting of cells or sections, it will use the <code>UITableViewRowAnimation</code> style of <code>UITableViewRowAnimationAutomatic</code> under the hood, so all of your animations will look great. This style was added in iOS 5.</p>\n\n<h2 id=\"example-app\" data-level=\"3\">Example App</h2>\n\n<p>So for fun (and to aid me in developing the library, determine its needs) I started using <code>JMStaticTableViewController</code> to attempt to re-create the built-in iOS Settings application. This exists in a sort of “half-finished” state inside <a href=\"http://bitly.com/OGCvCY\">the library’s Github repo</a></p>\n\n<p>Some things to try in it are: </p>\n\n<ul>\n<li><p>Wi-Fi, go into the Wi-Fi section and notice how the rows appear after “searching for networks” (this is obviously simulated). Also try disabling and re-enabling Wi-Fi. Notice how the rows appear and disappear with correct animations. </p></li>\n<li><p>The Notifications section also demonstrates showing some content.</p></li>\n<li><p>Cells that shouldn’t be “selectable” (like cells containing <code>UISwitch</code> controls) aren’t selectable.</p></li>\n<li><p>Normal <code>UITableViewDelegate</code> methods still work, so implementing things like like adding a <code>UIActivityIndicatorView</code> next to a section title are no more or less complicated than before.</p></li>\n</ul>\n\n<p>It is, like I mentioned, unfinished, meant merely as a tool for you to checkout and get some perspective on how the library might be used in the “real world”. More completion of the example as well as any other examples are very welcome, please feel free to submit pull requests.</p>\n\n<h3 id=\"example-app-screenshots\" data-level=\"4\">Example App Screenshots</h3>\n\n<div style=\"width: 84%; margin: 10px auto;\">\n<img src=\"https://deallocatedobjects.com/media/ce0efed305f3.png\" width=\"42%\" style=\"float: left; margin-right: 10px;\" alt=\"Example app recreating the iOS Settings screen with Airplane Mode, Wi-Fi, Notifications and more\" loading=\"lazy\" decoding=\"async\">&nbsp;&nbsp;\n<img src=\"https://deallocatedobjects.com/media/e46cbed96886.png\" width=\"42%\" style=\"float: left; margin-bottom: 10px;\" alt=\"Example app&#39;s Wi-Fi Networks screen, Wi-Fi on and searching for networks\" loading=\"lazy\" decoding=\"async\">&nbsp;&nbsp;\n<img src=\"https://deallocatedobjects.com/media/e3dfc887061a.png\" width=\"42%\" style=\"float: left; margin-right: 10px;\" alt=\"Example app&#39;s Wi-Fi Networks screen listing several available networks\" loading=\"lazy\" decoding=\"async\">&nbsp;&nbsp;\n<img src=\"https://deallocatedobjects.com/media/3b61739a0a97.png\" width=\"42%\" style=\"float: left; margin-bottom: 10px;\" alt=\"Example app&#39;s Wi-Fi Networks screen with Wi-Fi switched off\" loading=\"lazy\" decoding=\"async\">&nbsp;&nbsp;\n<img src=\"https://deallocatedobjects.com/media/40d054a9c0f4.png\" width=\"42%\" style=\"float: left; margin-bottom: 20px;\" alt=\"Example app&#39;s Notifications screen with sort options and a Weather Widget row\" loading=\"lazy\" decoding=\"async\">\n</div>\n\n<div style=\"clear: both;\"></div>\n\n<h2 id=\"ios-version-compatability\" data-level=\"3\">iOS Version Compatability</h2>\n\n<p><code>JMStaticContentTableViewController</code> supports iOS 5 and up.</p>\n\n<h2 id=\"adding-to-your-project\" data-level=\"3\">Adding To Your Project</h2>\n\n<h3 id=\"cocoapods-the-new-easy-way\" data-level=\"4\">CocoaPods (The New Easy Way)</h3>\n\n<p>If you are using <a href=\"http://cocoapods.org\">CocoaPods</a> then just add this line to your <code>Podfile</code>:</p>\n<figure class=\"code\" data-lang=\"ruby\"><figcaption><span class=\"lang\">Ruby</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">dependency </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">'JMStaticContentTableViewController'</span></span></code></pre></figure>\n<p>Now run <code>pod install</code> to install the dependency.</p>\n\n<h3 id=\"manually-the-old-hard-way\" data-level=\"4\">Manually (The Old Hard Way)</h3>\n\n<p><a href=\"https://github.com/jakemarsh/JMStaticContentTableViewController/zipball/master\">Download</a> the source files or add it as a <a href=\"https://schacon.github.io/git/user-manual.html#submodules\">git submodule</a>. Here’s how to add it as a submodule:</p>\n<figure class=\"code\" data-lang=\"bash\"><figcaption><span class=\"lang\">Shell</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">$</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> cd</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> YourProject</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">$</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> git</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> submodule</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> add</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> https://github.com/jakemarsh/JMStaticContentTableViewController.git</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> Vendor/JMStaticContentTableViewController</span></span></code></pre></figure>\n<p>Add all of the files inside the folder named “JMStaticContentTableViewController” to your project.</p>\n\n<h3 id=\"arc\" data-level=\"4\">ARC</h3>\n\n<p><code>JMStaticContentTableViewController</code> uses <a href=\"http://clang.llvm.org/docs/AutomaticReferenceCounting.html\">Automatic Reference Counting (ARC)</a>. You should be using ARC too, it’s the future. If your project doesn’t use ARC, you will need to set the <code>-fobjc-arc compiler</code> flag on all of the <code>JMStaticContentTableViewController</code> source files. To do this in Xcode, go to your active target and select the “Build Phases” tab. In the “Compiler Flags” column, set <code>-fobjc-arc</code> for each of the <code>JMStaticContentTableViewController</code> source files.</p>\n\n<h3 id=\"this-library-is-bad-and-you-should-feel-bad\" data-level=\"4\">“This Library is Bad, and You Should Feel Bad”</h3>\n\n<p><center><img src=\"https://deallocatedobjects.com/media/7f6b6bb7dfe1.jpg\" title=\"This Library is Bad, and You Should Feel Bad\" alt=\"Futurama Zoidberg meme reading &quot;This library is bad and you should feel bad&quot;\" loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"300\"></center></p>\n\n<p>This is my first try at building a system like this for this purpose, there are already a ton of things I plan on “fixing”, improving, and re-doing. I wouldn’t really be a good developer if I didn’t hate all my code once I was done would ? ;)</p>\n\n<p>I’m totally open to suggestions/fixes/hate mail/etc just let me know in a pull request, issue or even on twitter, I’m <a href=\"http://twitter.com/jakemarsh\">@jakemarsh</a>.</p>\n\n<p>That being said, this is a very opinionated library. It makes assumptions and defines conventions that might not fit perfectly with everyone’s codebase or app. If you are one of those people, please feel free to submit a pull request so we can talk about it and maybe get some of your desired changes worked in.</p>\n\n<p><a href=\"http://bitly.com/OGCvCY\">Check it out on Github here</a>.</p>","created_at":"2013-11-16T05:10:25.544Z","updated_at":"2014-10-27T00:18:34.833Z"}