Latest 1.0.1.1
Homepage https://github.com/azizuysal/AUPickerCell
License MIT
Platforms ios 10.0
Authors

Language
Carthage compatible
CocoaPods compatible

Embedded picker view for table cells.

AUPickerCell animated GIF

Requirements

AUPickerCell requires Swift 4.0 and Xcode 9.0.

Installation

CocoaPods

You can use CocoaPods to integrate AUPickerCell with your project.

Simply add the following line to your Podfile:

pod "AUPickerCell"

And run pod update in your project directory.

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

brew update
brew install carthage

To integrate AUPickerCell into your Xcode project using Carthage, specify it in your Cartfile:

github "azizuysal/AUPickerCell"

Run carthage update to build the framework and drag the built AUPickerCell.framework into your Xcode project.

Manually

You can integrate AUPickerCell manually into your project simply by dragging AUPickerCell.framework onto Linked Frameworks and Libraries section in Xcode, or by copying AUPickerCell.swift source file in to your project.

Usage

You can use AUPickerCell in your UITableView like any other UITableViewCell subclass:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  let cell = AUPickerCell(type: .default, reuseIdentifier: "TableCell")
  cell.values = ["One", "Two", "Three"]
  cell.selectedRow = 1
  cell.leftLabel.text = "Options"
  return cell
}

Afterwards, implement the following boilerplate in your UITableViewDelegate to support automatic cell expansion to display the picker:

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  if let cell = tableView.cellForRow(at: indexPath) as? AUPickerCell {
    return cell.height
  }
  return super.tableView(tableView, heightForRowAt: indexPath)
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  tableView.deselectRow(at: indexPath, animated: true)
  if let cell = tableView.cellForRow(at: indexPath) as? AUPickerCell {
    cell.selectedInTableView(tableView)
  }
}

The above example produces a cell with an embedded UIPickerView but you can just as easily create a cell with an embedded UIDatePicker by setting the picker type to .date, as below:

let cell = AUPickerCell(type: .date, reuseIdentifier: "PickerDateCell")

Upon user interaction, cell will auto update the right label text to reflect user’s choice. You can also implement a delegate method to be notified of user’s selection:

class MyViewController: UITableViewController, AUPickerCellDelegate {
  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = AUPickerCell(type: .default, reuseIdentifier: "PickerDefaultCell")
    cell.delegate = self
    ...
  }
}

func auPickerCell(_ cell: AUPickerCell, didPick row: Int, value: Any) {
  self.pickedValue = value as! String
  ...
}

or, in the case of a date picker:

func auPickerCell(_ cell: AUPickerCell, didPick row: Int, value: Any) {
  self.pickedDate = value as! Date
  ...
}

License

The MIT License (MIT)

Latest podspec

{
    "name": "AUPickerCell",
    "version": "1.0.1.1",
    "summary": "Embedded picker view for table cells",
    "description": "A UITableViewCell with an embedded UIPickerView for dates or strings.",
    "homepage": "https://github.com/azizuysal/AUPickerCell",
    "license": {
        "type": "MIT",
        "file": "LICENSE.md"
    },
    "authors": {
        "Aziz Uysal": "[email protected]"
    },
    "social_media_url": "https://twitter.com/azizuysal",
    "source": {
        "git": "https://github.com/azizuysal/AUPickerCell.git",
        "tag": "1.0.1.1"
    },
    "platforms": {
        "ios": "10.0"
    },
    "swift_version": "4.0",
    "source_files": "AUPickerCell/AUPickerCell/*.{swift}"
}

Pin It on Pinterest

Share This