<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>UITableViewCell on Andrew Bancroft</title>
    <link>https://www.andrewcbancroft.com/tags/uitableviewcell/</link>
    <description>Recent content about iOS development with Swift in UITableViewCell  from Andrew Bancroft.</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 12 Feb 2015 13:00:50 +0000</lastBuildDate>
    
        <atom:link href="https://www.andrewcbancroft.com/tags/uitableviewcell/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Custom UITableViewCell for Text Input in Swift</title>
      <link>https://www.andrewcbancroft.com/2015/02/12/custom-uitableviewcell-text-input-swift/</link>
      <pubDate>Thu, 12 Feb 2015 13:00:50 +0000</pubDate>
      
      <guid>https://www.andrewcbancroft.com/2015/02/12/custom-uitableviewcell-text-input-swift/</guid>
      <description>&lt;p&gt;The need to collect data via text input is a common in many applications. This walk-through showcases how to create a custom &lt;code&gt;UITableViewCell&lt;/code&gt; for accepting text input within a &lt;code&gt;UITableView&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;tableview-data-entry&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;table-views-for-data-entry&#34;&gt;Table Views for Data Entry?&lt;/h3&gt;
&lt;p&gt;Table views provide nice, built-in styles that present a form-like view for collecting data from your users. They also have inherent scrolling capabilities. Finally, there is some handy keyboard handling, such as auto-scrolling to avoid covering up a data entry cell, or hiding the keyboard when the user scrolls the Table View. Both of those are challenging to get right if you were to do implement a data entry form some other way.&lt;/p&gt;
&lt;p&gt;Many of Apple&amp;rsquo;s own UIs utilize table views to collect data from the user (think Settings, Calendar, Reminders).&lt;/p&gt;
&lt;p&gt;For those reasons, I think a table view is a really convenient choice for collecting data from a user.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;step-by-step&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;step-by-step-walkthrough&#34;&gt;Step by Step Walkthrough&lt;/h3&gt;
&lt;div class=&#34;resources&#34;&gt;
  &lt;div class=&#34;resources-header&#34;&gt;
    Resources
  &lt;/div&gt;
  &lt;ul class=&#34;resources-content&#34;&gt;
    &lt;li&gt;
      &lt;i class=&#34;fab fa-github fa-lg&#34;&gt;&lt;/i&gt; &lt;a href=&#34;https://github.com/andrewcbancroft/CustomTextInputTableViewCell&#34;title=&#34;Custom Text Input TableView Cell Example&#34;&gt;Example Xcode Project&lt;/a&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a name=&#34;drag-tableview&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;drag-a-table-view-to-storyboard&#34;&gt;Drag a table view to Storyboard&lt;/h4&gt;
&lt;p&gt;Assuming that you have a View Controller already on the Storyboard design surface, drag a table view onto the Storyboard scene.&lt;br&gt;
&lt;a href=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_%E2%80%94_Edited_and_Edit_Post_%E2%80%B9_Andrew_Bancroft_%E2%80%94_WordPress_and_AddVerseControllerTests_swift.png&#34;&gt;&lt;img src=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_—_Edited_and_Edit_Post_‹_Andrew_Bancroft_—_WordPress_and_AddVerseControllerTests_swift-1024x569.png&#34; alt=&#34;Drag Table View to Storyboard&#34; width=&#34;1024&#34; height=&#34;569&#34; class=&#34;alignnone size-large wp-image-11324&#34; srcset=&#34;https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_—_Edited_and_Edit_Post_‹_Andrew_Bancroft_—_WordPress_and_AddVerseControllerTests_swift-1024x569.png 1024w, https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_—_Edited_and_Edit_Post_‹_Andrew_Bancroft_—_WordPress_and_AddVerseControllerTests_swift-300x167.png 300w&#34; sizes=&#34;(max-width: 1024px) 100vw, 1024px&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;data-source-delegate&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;wire-up-table-view-data-source-and-delegate&#34;&gt;Wire up table view data source and delegate&lt;/h4&gt;
&lt;p&gt;For this step it&amp;rsquo;s helpful to have the document outline pane visible. Selecting the Table View from the document outline and subsequently Control + Click + Dragging to the View Controller icon on the Storyboard scene will allow you to link the table view&amp;rsquo;s dataSource and delegate properties to the View Controller.&lt;br&gt;
&lt;a href=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Ctrl-Click-Drag-to-set-DataSource-and-Delegate.png&#34;&gt;&lt;img src=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Ctrl-Click-Drag-to-set-DataSource-and-Delegate-1024x507.png&#34; alt=&#34;Ctrl+Click-Drag to set DataSource and Delegate&#34; width=&#34;1024&#34; height=&#34;507&#34; class=&#34;alignnone size-large wp-image-11683&#34; srcset=&#34;https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Ctrl-Click-Drag-to-set-DataSource-and-Delegate-1024x507.png 1024w, https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Ctrl-Click-Drag-to-set-DataSource-and-Delegate-300x148.png 300w&#34; sizes=&#34;(max-width: 1024px) 100vw, 1024px&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Set-DataSource-and-Delegate.png&#34;&gt;&lt;img src=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Set-DataSource-and-Delegate-1024x508.png&#34; alt=&#34;Set DataSource and Delegate&#34; width=&#34;1024&#34; height=&#34;508&#34; class=&#34;alignnone size-large wp-image-11354&#34; srcset=&#34;https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Set-DataSource-and-Delegate-1024x508.png 1024w, https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Set-DataSource-and-Delegate-300x149.png 300w&#34; sizes=&#34;(max-width: 1024px) 100vw, 1024px&#34; /&gt;&lt;/a&gt;&lt;br&gt;
Note that you&amp;rsquo;ll need to perform the Control + Click + Drag maneuver twice to set both the dataSource and the delegate.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;dismiss-keyboard&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;configure-keyboard-dismissal-for-table-view&#34;&gt;Configure keyboard dismissal for table view&lt;/h4&gt;
&lt;p&gt;With the attributes inspector selected in the utilities pane, scroll down to the Keyboard option and set it to &amp;ldquo;Dismiss on drag”.&lt;br&gt;
&lt;a href=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Configure-Keyboard-Dismissal1.png&#34;&gt;&lt;img src=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Configure-Keyboard-Dismissal1-1024x509.png&#34; alt=&#34;Configure Keyboard Dismissal&#34; width=&#34;1024&#34; height=&#34;509&#34; class=&#34;alignnone size-large wp-image-11357&#34; srcset=&#34;https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Configure-Keyboard-Dismissal1-1024x509.png 1024w, https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Configure-Keyboard-Dismissal1-300x149.png 300w&#34; sizes=&#34;(max-width: 1024px) 100vw, 1024px&#34; /&gt;&lt;/a&gt;&lt;br&gt;
This can be helpful if you&amp;rsquo;d like the keyboard to automatically hide itself when the user scrolls the table view.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;constraints&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;set-constraints-increase-prototype-cells-count&#34;&gt;Set constraints, increase prototype cells count&lt;/h4&gt;
&lt;p&gt;Use the document outline to set constraints. With the attributes inspector selected in the utilities pane, select &amp;ldquo;Dynamic Prototypes” for the Content property, and set the Prototype Count property to 1 (or more, depending on your needs).&lt;br&gt;
&lt;a href=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Set-Constraints-and-Prototype-Cells1.png&#34;&gt;&lt;img src=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Set-Constraints-and-Prototype-Cells1-1024x508.png&#34; alt=&#34;Set Constraints and Prototype Cells&#34; width=&#34;1024&#34; height=&#34;508&#34; class=&#34;alignnone size-large wp-image-11352&#34; srcset=&#34;https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Set-Constraints-and-Prototype-Cells1-1024x508.png 1024w, https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Set-Constraints-and-Prototype-Cells1-300x149.png 300w&#34; sizes=&#34;(max-width: 1024px) 100vw, 1024px&#34; /&gt;&lt;/a&gt;&lt;br&gt;
Configuring constraints on the table view will ensure that it displays properly on all device sizes and orientations.&lt;/p&gt;
&lt;p&gt;In this particular example, there&amp;rsquo;s only one kind of prototype cell that I want the table view to display. If I had multiple prototypes, I&amp;rsquo;d increase the prototype cells count to match the number of prototypes I had.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;drag-text-field&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;drag-text-field-to-cell-increase-text-field-width&#34;&gt;Drag text field to cell, increase text field width&lt;/h4&gt;
&lt;p&gt;Drag a text field into the cell&amp;rsquo;s contents and use Xcode&amp;rsquo;s blue guides to adjust the width so that it takes up the whole cell.&lt;br&gt;
&lt;a href=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_%E2%80%94_Edited_and_Main_storyboard_1.png&#34;&gt;&lt;img src=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_—_Edited_and_Main_storyboard_1-1024x622.png&#34; alt=&#34;Drag Text Field to Cell&#34; width=&#34;1024&#34; height=&#34;622&#34; class=&#34;alignnone size-large wp-image-11325&#34; srcset=&#34;https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_—_Edited_and_Main_storyboard_1-1024x622.png 1024w, https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_—_Edited_and_Main_storyboard_1-300x182.png 300w, https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_—_Edited_and_Main_storyboard_1.png 1488w&#34; sizes=&#34;(max-width: 1024px) 100vw, 1024px&#34; /&gt;&lt;/a&gt;&lt;br&gt;
Now comes the customization of the prototype cell itself. Since we&amp;rsquo;re designing it for text input, we&amp;rsquo;ll use a text field as the contents of the table view cell prototype.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;configure-text-field-constraints&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;configure-text-field-constraints-and-border&#34;&gt;Configure Text Field Constraints and Border&lt;/h4&gt;
&lt;p&gt;Use the document outline to set constraints for the text field. With the text field selected, and the attributes inspector selected in the utilities pane, set the Border Style property to the style you prefer.&lt;br&gt;
&lt;a href=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Configure-Text-Field-Constraints-and-Border.png&#34;&gt;&lt;img src=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Configure-Text-Field-Constraints-and-Border-1024x508.png&#34; alt=&#34;Configure Text Field Constraints and Border&#34; width=&#34;1024&#34; height=&#34;508&#34; class=&#34;alignnone size-large wp-image-11350&#34; srcset=&#34;https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Configure-Text-Field-Constraints-and-Border-1024x508.png 1024w, https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Configure-Text-Field-Constraints-and-Border-300x149.png 300w&#34; sizes=&#34;(max-width: 1024px) 100vw, 1024px&#34; /&gt;&lt;/a&gt;&lt;br&gt;
Configuring constraints on the text field will ensure that it displays properly on all device sizes and orientations.&lt;/p&gt;
&lt;p&gt;Depending on your taste / needs, you can change the border style from rounded to none, or whichever other border style is most appealing for your app.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;text-input-cell-class&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;create-new-textinputtableviewcell-class&#34;&gt;Create new TextInputTableViewCell class&lt;/h4&gt;
&lt;p&gt;Add a new .swift file named TextInputTableViewCell to your project. Create a new class in that file called &lt;code&gt;TextInputTableViewCell&lt;/code&gt; which inherits from &lt;code&gt;UITableViewCell&lt;/code&gt;.&lt;br&gt;
&lt;a href=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_and_Main_storyboard.png&#34;&gt;&lt;img src=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_and_Main_storyboard-1024x567.png&#34; alt=&#34;Create new class - TextInputTableViewCell&#34; width=&#34;1024&#34; height=&#34;567&#34; class=&#34;alignnone size-large wp-image-11330&#34; srcset=&#34;https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_and_Main_storyboard-1024x567.png 1024w, https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_and_Main_storyboard-300x166.png 300w&#34; sizes=&#34;(max-width: 1024px) 100vw, 1024px&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;ib-outlet&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;create-an-iboutlet-between-the-text-field-and-the-textinputtableviewcell-class&#34;&gt;Create an IBOutlet between the text field and the TextInputTableViewCell class&lt;/h4&gt;
&lt;p&gt;Use the document outline to Control + Click + Drag and IBOutlet to the &lt;code&gt;TextInputTableViewCell&lt;/code&gt; class.&lt;br&gt;
&lt;a href=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Create-IBOutlet1.png&#34;&gt;&lt;img src=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Create-IBOutlet1-1024x512.png&#34; alt=&#34;Create IBOutlet&#34; width=&#34;1024&#34; height=&#34;512&#34; class=&#34;alignnone size-large wp-image-11684&#34; srcset=&#34;https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Create-IBOutlet1-1024x512.png 1024w, https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Create-IBOutlet1-300x150.png 300w&#34; sizes=&#34;(max-width: 1024px) 100vw, 1024px&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;implement-class&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;implement-textinputtableviewcell-class&#34;&gt;Implement TextInputTableViewCell class&lt;/h4&gt;
&lt;p&gt;An example implementation with a function for configuring the text field&amp;rsquo;s properties might look something like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kd&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;UIKit&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kd&#34;&gt;public&lt;/span&gt; &lt;span class=&#34;kd&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;TextInputTableViewCell&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;UITableViewCell&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kr&#34;&gt;@IBOutlet&lt;/span&gt; &lt;span class=&#34;kr&#34;&gt;weak&lt;/span&gt; &lt;span class=&#34;kd&#34;&gt;var&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;textField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;UITextField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;!&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 5&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 6&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kd&#34;&gt;public&lt;/span&gt; &lt;span class=&#34;kd&#34;&gt;func&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;configure&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(#&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;String&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;?,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;placeholder&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;String&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 7&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;n&#34;&gt;textField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 8&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;n&#34;&gt;textField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;placeholder&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;placeholder&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 9&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;n&#34;&gt;textField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;accessibilityValue&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;n&#34;&gt;textField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;accessibilityLabel&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;placeholder&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;13&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;a name=&#34;storyboard-setup&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;change-cell-class-in-storyboard-to-textinputtableviewcell&#34;&gt;Change cell class in Storyboard to TextInputTableViewCell&lt;/h4&gt;
&lt;p&gt;Use the document outline to select the Table View Cell. With the identity inspector selected in the utilities pane, change the Class property to your TextInputTableViewCell class.&lt;br&gt;
&lt;a href=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_%E2%80%94_Edited_and_Main_storyboard.png&#34;&gt;&lt;img src=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_—_Edited_and_Main_storyboard-1024x513.png&#34; alt=&#34;Change Cell Class to TextInputCell&#34; width=&#34;1024&#34; height=&#34;513&#34; class=&#34;alignnone size-large wp-image-11328&#34; srcset=&#34;https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_—_Edited_and_Main_storyboard-1024x513.png 1024w, https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_—_Edited_and_Main_storyboard-300x150.png 300w&#34; sizes=&#34;(max-width: 1024px) 100vw, 1024px&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;reuse-identifier&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;set-reuse-identifier&#34;&gt;Set reuse identifier&lt;/h4&gt;
&lt;p&gt;With the Table View Cell still selected in the document outline, select the attribute inspector in the utilities pane and change the Identifier property to &amp;ldquo;TextInputCell” (or some other string that&amp;rsquo;s easily remembered).&lt;br&gt;
&lt;a href=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_%E2%80%94_Edited_2.png&#34;&gt;&lt;img src=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_—_Edited_2-1024x511.png&#34; alt=&#34;Set Reuse Identifier&#34; width=&#34;1024&#34; height=&#34;511&#34; class=&#34;alignnone size-large wp-image-11323&#34; srcset=&#34;https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_—_Edited_2-1024x511.png 1024w, https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Main_storyboard_—_Edited_2-300x150.png 300w&#34; sizes=&#34;(max-width: 1024px) 100vw, 1024px&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;implement-datasource-delegate&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;implement-table-view-data-source-and-delegate-methods&#34;&gt;Implement table view data source and delegate methods&lt;/h4&gt;
&lt;p&gt;In the View Controller, specify that it adopts the &lt;code&gt;UITableViewDataSource&lt;/code&gt; and &lt;code&gt;UITableViewDelegate&lt;/code&gt; protocols. Implement the appropriate protocol methods.&lt;br&gt;
I&amp;rsquo;ve written a &lt;a href=&#34;http://www.andrewcbancroft.com/2014/11/24/swift-uitableviewdatasource-cheat-sheet/&#34;&gt;cheat sheet&lt;/a&gt; for this, but I&amp;rsquo;ll also provide the following sample implementation of the mai &lt;code&gt;ViewController&lt;/code&gt; class:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kd&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;UIKit&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kd&#34;&gt;public&lt;/span&gt; &lt;span class=&#34;kd&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;ViewController&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;UIViewController&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;UITableViewDataSource&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;UITableViewDelegate&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kd&#34;&gt;public&lt;/span&gt; &lt;span class=&#34;kd&#34;&gt;func&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;tableView&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tableView&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;UITableView&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;numberOfRowsInSection&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;section&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;Int&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 5&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// Create 1 row as an example&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 6&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 7&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 8&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kd&#34;&gt;public&lt;/span&gt; &lt;span class=&#34;kd&#34;&gt;func&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;tableView&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tableView&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;UITableView&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;cellForRowAtIndexPath&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;indexPath&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;NSIndexPath&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;UITableViewCell&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 9&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;kd&#34;&gt;let&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;cell&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;tableView&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dequeueReusableCellWithIdentifier&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;TextInputCell&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;TextInputTableViewCell&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;n&#34;&gt;cell&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;configure&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;placeholder&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;Enter some text!&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;cell&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;13&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;14&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Lines 9 and 11 are of most importance. Notice that I&amp;rsquo;m dequeueing a TextInputCell, which is what I set the reuse identifier of my cell to be. I&amp;rsquo;m also casting the dequeued cell as a TextInputTableViewCell so that it can be configured (line 11)&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;run-in-simulator&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;run-in-simulator&#34;&gt;Run in simulator&lt;/h4&gt;
&lt;p&gt;&lt;a href=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Simulator-Output.png&#34;&gt;&lt;img src=&#34;http://www.andrewcbancroft.com/wp-content/uploads/2015/02/Simulator-Output.png&#34; alt=&#34;Simulator Output&#34; width=&#34;473&#34; height=&#34;869&#34; class=&#34;alignnone size-full wp-image-11365&#34; srcset=&#34;https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Simulator-Output.png 473w, https://www.andrewcbancroft.com/wp-content/uploads/2015/02/Simulator-Output-163x300.png 163w&#34; sizes=&#34;(max-width: 473px) 100vw, 473px&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;wrapping-up&#34;&gt;Wrapping up&lt;/h3&gt;
&lt;p&gt;In this walkthrough, my goal was to show how to take advantage of a table view&amp;rsquo;s inherent styles, scrolling capabilities, and keyboard handling to make form-like text input easier. We created a custom subclass of UITableViewCell to accomplish this task. Take a look at the &lt;a href=&#34;https://github.com/andrewcbancroft/CustomTextInputTableViewCell&#34;&gt;example published to GitHub&lt;/a&gt; to dive in further and explore the walkthrough in more depth.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;share&#34; class=&#34;jump-target&#34;&gt;&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>