Skip to content

macabeus/InputStepByStep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

19 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Version License Platform

InputStepByStep

๐Ÿ“ A input view for tvOS, useful for testing purposes.

"Hey, but it is horrible to enter input in AppleTV!"
Yes, I know, but in some cases it is useful for testing, when you are using simulator or testing in physical device with iPhone.

You can download this repository and see this example app.

How to use

Install

In Podfile add

pod 'InputStepByStep'

and use pod install.

Setup

Storyboard

  1. Create a Container View
  2. Change the View Controller for Collection View Controller
  3. Set InputStepByStep as a custom class

Set fields

Your controller that will manager a InputStepByStep need subscriber the protocol InputStepByStepProtocol

Minimal example:

class ViewController: UIViewController, InputStepByStepProtocol {
    
    @IBOutlet weak var container: UIView!
    var containerStepByStep: InputStepByStep?
        
    var configList: [CellCreateGrid] = [ // set the inputs
        .name("Login"),
        .input(name: "user", label: "User"),
        .input(name: "password", label: "Password"),
        .input(name: "email", label: "E-Mail"),
        
        .name("Personal infos"),
        .input(name: "firtname", label: "Your first name"),
        .input(name: "lastname", label: "Your last name"),
        
        .finish() // you need set the ".finish" at the end of "configList"
    ]
    
    func cellFinishAction(inputValues: [String: [String: String]]) { // when the user click in green button
        if let user = inputValues["Login"]?["user"],
            let password = inputValues["Login"]?["password"],
            let email = inputValues["Login"]?["email"] {
            
            print("create account with login \(user), password \(password) and email \(email)")
        }
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        
        if segue.identifier == "segueInputStepyBtStep" {
            self.containerStepByStep = (segue.destination as! InputStepByStep)
            self.containerStepByStep!.delegate = self // set a delegate where
        }
    }
}

The configList is a list of inputs that InputStepByStep will show.
You use .name(String) to create a division and .input(name: String, label: String to create a input. And, at the end, you need add .finish() to create a green button.

The function cellFinishAction(inputValues:) is called when the green button is clicked.
The parameters in inputValues is a dictionary with key as the name of division ("Login" or "Personal infos" in example) and value is another dictionary, with key as the name of input ("email", for example) and the value is the value setted by user.