skip to Main Content

I’m currently working on a texting app and to do that I created a table view controller. I want to add a textfield the very bottom of the table view controller. Xcode wouldn’t let me add a text field in the controller so I added a container view where I was able to put a textfield inside.

The only issue I have now is placing that container view to the very bottom where the user is able to type in a text (which is typical in any texting app).

3

Answers


  1. Chosen as BEST ANSWER

    Never mind. Instead of creating a table view controller manually create one. Allows for more flexibility.


  2. The short answer is that you can’t add anything to a table view controller. It is a special purpose view controller that manages a table view controller and nothing else. I’ve always thought this was kind of silly, but it’s true.

    What you should do is to start with a custom subclass of UIViewController as your parent view controller. Add a container view to that, and drag an embed segue to a table view controller. Your view controller now contains a table view controller.

    Now add other text fields, buttons, or other view components to the parent view controller.

    Edit

    As SmartCat pointed out in their answer, you could also manage a table view directly in your view controller. There is nothing saying that you must use a UITableViewController.

    Login or Signup to reply.
  3. A UITableViewController is very limiting. You are stuck with a full-(viewController view) UITableView. About the best you could do to add more beyond the rows is insert a custom header or footer to the table view.

    Although the other answer recommends putting the UITableViewController into a container view within a subclass of UIViewController, and that would work, it may lead you to more complexity than is needed. It would also definitely limit your ability to further customize that container view to have something beyond just a UITableView.

    That strategy would enable you to customize around it with whatever else you put into the parent UIViewController, but it’s still forcing an area to be stuck with just a UITableView, which may bother you in future modifications to your app as you’ll have to rearrange code to move to the UIViewController as your UI evolves.

    I never use UITableViewController in my apps. It brings very little to the table, and what it does add, you can easily replicate in your own code within your UIViewController subclass – if you even care about those minor things. I just put a UITableView directly into my UIViewController’s view and have my UIViewController also be the UITableViewDelegate and UITableViewDataSource by implementing those protocols.

    You can see this SO answer for details on what little a UITableViewController adds.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search