Latest 0.2.3
Homepage https://github.com/jday001/DataEntryToolbar
License MIT
Platforms ios 7.0, requires ARC
Authors

CI Status
Version
License
Platform

DataEntryToolbar is a subclass of UIToolbar intended for use as the input accessory view of a keyboard or picker, providing Next, Previous, & Done buttons to navigate up and down a dynamic tableView.

Example Setup

Create an instance of DataEntryToolbar in your TableViewController subclass. Be sure to provide your tableView in the initializer:

private lazy var dataEntryToolbar: DataEntryToolbar? = {
    if let dataEntryToolbar = DataEntryToolbar(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 44), 
        table:self.tableView) as DataEntryToolbar? {

        // implement closures to be notified when buttons are tapped for additional customization:
        ...
        dataEntryToolbar.didTapDoneButtonFromTextField = { (lastActiveTextField) in
            if let textField = lastActiveTextField {
                self.textFieldShouldReturn(textField)
            }
        }
        ...

        return dataEntryToolbar
    } else {
        return nil
    }
}()

In cellForRowAtIndexPath, set a DataEntryToolbar instance as the inputAccessoryView for your cell’s text field. Also, add that text field to the tableTextFields dictionary using the current indexPath as key:

override func tableView(tableView: UITableView, cellForRowAtIndexPath 
    indexPath: NSIndexPath) -> UITableViewCell {

    switch (indexPath.section) {

    // first section -- basic info
    case TableSections.BasicInfo.rawValue:
        switch (indexPath.row) {
        case 0:
            let nameCell = tableView.dequeueReusableCellWithIdentifier("NameCell", 
                forIndexPath: indexPath) as JDCustomTextFieldCell
            nameCell.textField.inputAccessoryView = self.dataEntryToolbar
            self.dataEntryToolbar?.tableTextFields[indexPath] = nameCell.textField
            nameCell.textField.text = self.textFieldData[indexPath]
            return nameCell
        }
        `...`
    }
    `...`
}

You can customize the appearance of the toolbar in several ways. The height can be specified in the initializer, or you can change the color of the toolbar itself or its buttons:

// adjust bar's tint color
self.dataEntryToolbar.barTintColor = UIColor.darkGrayColor()

// adjust prev/next button tint colors
self.dataEntryToolbar.previousButton.tintColor = UIColor.blueColor()

Note

If using a subclass of UITableViewController, the active text field will always be automatically scrolled into a position above the keyboard so the user can see it. If you are using a UITableView inside a regular UIViewController, you will have to implement this functionality yourself.

Suggestions or improvements always welcome!

Alt text

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

DataEntryToolbar is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "DataEntryToolbar"

Author

jeff, [email protected]

License

DataEntryToolbar is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "DataEntryToolbar",
    "version": "0.2.3",
    "summary": "A subclass of UIToolbar used to navigate up and down a dynamic tableView's text fields'.",
    "description": "n                    DataEntryToolbar is a subclass of UIToolbar intended for use as the input accessory view of a keyboard or picker, providing Next, Previous, & Done buttons to navigate up and down a dynamic tableView.nn                    To set up:n                    - Set a `DataEntryToolbar` instance as the inputAccessoryView of `UITextFields` you want to controln                    - Add textFields to `tableTextFields` in cellForRowAtIndexPath, using the textField's cell's indexPath as a keyn                    - If you want to be notified when a user taps one of the navigation buttons, implement the necessary closuresn                    - The look and feel of the toolbar and its buttons can be customized as you would with any toolbar (i.e. barStyle, barTintColor, or button tintColor properties)nn",
    "homepage": "https://github.com/jday001/DataEntryToolbar",
    "license": "MIT",
    "authors": {
        "jeff": "[email protected]"
    },
    "source": {
        "git": "https://github.com/jday001/DataEntryToolbar.git",
        "tag": "0.2.3"
    },
    "social_media_url": "https://twitter.com/jday001",
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "source_files": "Source/*.swift",
    "resource_bundles": {
        "DataEntryToolbar": [
            "Pod/Assets/*.png"
        ]
    }
}

Pin It on Pinterest

Share This