https://github.com/cbess/cbeditlistviewcontroller
A simple, but potentially powerful UITableViewController that handles CRUD operations and iPhone popover presentation.
https://github.com/cbess/cbeditlistviewcontroller
Last synced: 3 months ago
JSON representation
A simple, but potentially powerful UITableViewController that handles CRUD operations and iPhone popover presentation.
- Host: GitHub
- URL: https://github.com/cbess/cbeditlistviewcontroller
- Owner: cbess
- License: mit
- Created: 2015-06-18T04:27:47.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-08-25T23:17:47.000Z (almost 7 years ago)
- Last Synced: 2025-01-17T04:45:19.540Z (5 months ago)
- Language: Objective-C
- Homepage:
- Size: 37.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CBEditListViewController
A simple, but powerful (probably) UITableViewController that handles CRUD operations.
## Notes
This sample provides a complete create/insert, list, update/change, and delete UITableViewController.
The actions for the CRUD operations can be customized.## Usage
Swift example with [Realm](http://realm.io) *v0.94.0* database storage.
```swift
import UIKit
import RealmSwiftclass GroupsViewController: CBEditListViewController {
var groups: Results!
let realm = Realm()
override func viewDidLoad() {
super.viewDidLoad()
addListItemViewCell = UITableViewCell(style: .Default, reuseIdentifier: "add")
addListItemViewCell.textLabel?.text = NSLocalizedString("Add Group", comment: "")
navigationItem.rightBarButtonItem = editButtonItem()
reloadItems()
}
override func cellIdentifierAtIndexPath(indexPath: NSIndexPath!) -> String! {
return "itemcell"
}
override func configureCell(cell: UITableViewCell!, indexPath: NSIndexPath!) {
let theCell = cell as! CBEditListViewCell
theCell.textField?.text = groups[indexPath.row].name
}
// MARK: - Misc
func reloadItems() {
groups = realm.objects(Group)
items = NSMutableArray(array: Array(groups.generate()))
}
// MARK: - List Actions
override func willRemoveListItem(item: AnyObject!) {
let group = item as! Group
items.removeObject(group)
realm.write {
self.realm.delete(group)
}
}
override func didInsertListItemWithName(name: String!) {
let group = Group()
group.name = name
items.addObject(group)
realm.write {
self.realm.add(group, update: false)
}
}
override func didChangeListItem(item: AnyObject!, toName name: String!) {
let group = item as! Group
realm.write {
group.name = name
}
}
}```