Sign up with your email address to be the first to know about new products, VIP offers, blog features & more.

How to create a TableView without storyboard, start and finish UIViewControllers PROGRAMATICALLY

Steps to Completion:
  1. Create a singleView Project, delete the StoryBoard that Xcode created for you and remove Main as Main Interface from Project Deployment Info
  2. Edit AppDelegate.swift setting the root view controller (in this case it will be an UITableViewController)
  3. Create the constrollers and add subviews to controllers
  4. Define constraints for each UIView using Auto Layout with visual format
  5. Create transitions between controllers
 1. Create a singleView Project, delete the StoryBoard that Xcode created for you and remove Main as Main Interface from Project Deployment Info

No secrets here, since its an advanced tutorial i will assume you know what i am talking about. Everything is shown visually in the vídeo bellow.

2. Edit AppDelegate.swift setting the root view controller (in this case it will be an UITableViewController)
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.makeKeyAndVisible() //makes the key window and visible

let controller = MyCustomTableViewController()
let navigationController = UINavigationController(rootViewController: controller)
window?.rootViewController = navigationController
3. Create the controllers and add subviews to controllers

In this step controllers must be created. These controllers will be called by the buttons out in the table cells inside the table view controllers.

– To create a controller create a new file and subclass UIViewController
– Add subviews as needed. I will create just labels and buttons for each controller

4. Define constraints for each UIView using Auto Layout with visual format

In the vídeo there is a good explanation of how to use Auto Layout with visual formatting

5. Create transitions between controllers

To create transitions between controller the method showViewController(vc: UIViewController, sender: AnyObject?). But before calling it the controller must be prepared.

controller = SomeViewController() //this is the controller that will be presented
controller.modalPresentationStyle = UIModalPresentationStyle.PageSheet; //define presentation style
controller.modalTransitionStyle = UIModalTransitionStyle.CoverVertical //define transition style
showViewController(controller, sender: self) //calls the controller

No Comments Yet.

What do you think?

Your email address will not be published. Required fields are marked *