RETableViewManager
Data driven content manager for UITableView.
RETableViewManager allows to manage content of UITableView with ease, both forms and lists.
In its core RETableViewManager supports reusable cells based on corresponding data object class.
The general idea is to allow developers use their own UITableView and UITableViewController instances,
providing a layer that synchronizes data with cell appereance.
It is still in the early stages of development and it's highly not recommended to use it in production apps.
Requirements
- Xcode 4.6 or higher
- Apple LLVM compiler
- iOS 6.0 or higher
- ARC
Demo
Build and run the RETableViewManagerExample project in Xcode to see RETableViewManager in action.
API Quickstart
| Key Classes | |
|---|---|
| RETableViewManager | Main manager class. Each manager has multiple RETableViewSection sections. |
| RETableViewSection | Represents sections in RETableViewManager, each section has multiple RETableViewItem. |
| RETableViewItem | RETableViewItem is the root class of most RETableViewManager item hierarchies. Through RETableViewItem, items inherit a basic interface that communicates with RETableViewCell and RETableViewManager. |
| RETableViewCell | The RETableViewCell class defines the attributes and behavior of the cells that appear in UITableView objects. You should subclass RETableViewCell to obtain cell characteristics and behavior specific to your application's needs. By default, RETableViewCell is being mapped with RETableViewItem. |
| Styling | |
| RETableViewCellStyle | Provides style for RETableViewCell subclasses. You can define such properties as textFieldFont, cellHeight, backgroundImage and more. |
| Helper Controllers | |
| RETableViewOptionsController | Performs selection based on user input and provides result on completion. Should be used with RERadioItem. |
RETableViewManager includes a number of built-in items and cells that were mapped with each other so you don't have to.
| Built-in Items and Cells | ||
|---|---|---|
| Item Class | Cell Class | Description |
| RETextItem | RETableViewTextCell | Provides convenience for user text input. You can set a bunch of properties through RETextItem that you would normally find in UITextField. |
| RELongTextItem | RETableViewLongTextCell | Provides convenience for multiline user text input. You can set a bunch of properties through RELongTextItem that you would normally find in UITextView. |
| RENumberItem | RETableViewNumberCell | Provides convenience for user number input using REFormattedNumberField. |
| REBoolItem | RETableViewBoolCell | Provides convenience for user boolean input using UISwitch. |
| RERadioItem | RETableViewCell | Provides convenience for selecting a single option using RETableViewOptionsController. |
| REMultipleChoiceItem | RETableViewCell | Provides convenience for selecting multiple options using RETableViewOptionsController. |
| REFloatItem | RETableViewFloatCell | Provides convenience for adjusting float values from 0.0 to 1.0. |
| REDateTimeItem | RETableViewDateTimeCell | Provides convenience for adjusting NSDate object. |
| RECreditCardItem | RETableViewCreditCardCell | Provides convenience for user credit card input. Allows to enter credit card number, expiration date and security code all in one table cell. |
Examples
Simple Example
Subclass UITableViewController, remove all code from the implementation section and paste just this
(yes, now it's that easy to manage UITableView content):
- (void)viewDidLoad
{
[super viewDidLoad];
// Create the manager and assign it to be the delegate and datasource of your UITableView
//
_tableViewManager = [[RETableViewManager alloc] init];
self.tableView.delegate = _tableViewManager;
self.tableView.dataSource = _tableViewManager;
// Add a section
//
RETableViewSection *section = [[RETableViewSection alloc] initWithHeaderTitle:@"Test"];
[_tableViewManager addSection:section];
// Add a string
//
[section addItem:@"Just a simple NSString"];
// Add a basic cell with disclosure indicator
//
[section addItem:[RETableViewItem itemWithTitle:"String cell" accessoryType:UITableViewCellAccessoryDisclosureIndicator selectionHandler:^(RETableViewItem *item) {
NSLog(@"Test: %@", item);
}]];
}
Creating Sections Example
Section without a title:
RETableViewSection *section = [RETableViewSection section];
[_tableViewManager addSection:section];
Section with a title:
RETableViewSection *section = [RETableViewSection sectionWithHeaderTitle:@"Header"];
[_tableViewManager addSection:section];
Section with a title and a footer:
RETableViewSection *section = [RETableViewSection sectionWithHeaderTitle:@"Header" footerTitle:@"Footer"];
[_tableViewManager addSection:section];
Section with a custom title view:
RETableViewSection *section = [RETableViewSection sectionWithHeaderView:myCustomSectionHeaderView];
[_tableViewManager addSection:section];
Item to Cell Mapping Example
It's super easy to create custom mappings, the concept is similiar to UICollectionView.
For example, this how all NSString objects are being mapped with RETableViewCell:
[_tableViewManager registerClass:@"NSString" forCellWithReuseIdentifier:@"RETableViewCell"];
If you take a look at RETableViewManager Source Code you may find out how default mapping is performed:
- (void)setDefaultMapping
{
[self registerClass:@"__NSCFConstantString" forCellWithReuseIdentifier:@"RETableViewCell"];
[self registerClass:@"__NSCFString" forCellWithReuseIdentifier:@"RETableViewCell"];
[self registerClass:@"NSString" forCellWithReuseIdentifier:@"RETableViewCell"];
[self registerClass:@"RETableViewItem" forCellWithReuseIdentifier:@"RETableViewCell"];
[self registerClass:@"RERadioItem" forCellWithReuseIdentifier:@"RETableViewCell"];
[self registerClass:@"REBoolItem" forCellWithReuseIdentifier:@"RETableViewBoolCell"];
[self registerClass:@"RETextItem" forCellWithReuseIdentifier:@"RETableViewTextCell"];
[self registerClass:@"RELongTextItem" forCellWithReuseIdentifier:@"RETableViewLongTextCell"];
[self registerClass:@"RENumberItem" forCellWithReuseIdentifier:@"RETableViewNumberCell"];
[self registerClass:@"REFloatItem" forCellWithReuseIdentifier:@"RETableViewFloatCell"];
[self registerClass:@"REDateTimeItem" forCellWithReuseIdentifier:@"RETableViewDateTimeCell"];
[self registerClass:@"RECreditCardItem" forCellWithReuseIdentifier:@"RETableViewCreditCardCell"];
[self registerClass:@"REMultipleChoiceItem" forCellWithReuseIdentifier:@"RETableViewCell"];
}
Text (UITextField) and Number (REFormattedNumberField) Item Example
// Create the manager and assign it to be the delegate and datasource of your UITableView
//
_tableViewManager = [[RETableViewManager alloc] init];
self.tableView.delegate = _tableViewManager;
self.tableView.dataSource = _tableViewManager;
// Add a section
//
RETableViewSection *section = [[RETableViewSection alloc] initWithHeaderTitle:@"Test"];
[_tableViewManager addSection:section];
_textItem = [RETextItem itemWithTitle:@"Enter text" value:@""];
[section addItem:_textItem];
_numberItem = [RENumberItem itemWithTitle:@"Enter text" value:@"" placeholder:@"(123) 456-7890" format:@"(XXX) XXX-XXXX"];
[section addItem:_numberItem];
You can read _textItem.value and _numberItem.value later whenever you need them.
Bool Item (UISwitch) Example
// Create the manager and assign it to be the delegate and datasource of your UITableView
//
_tableViewManager = [[RETableViewManager alloc] init];
self.tableView.delegate = _tableViewManager;
self.tableView.dataSource = _tableViewManager;
// Add a section
//
RETableViewSection *section = [[RETableViewSection alloc] initWithHeaderTitle:@"Test"];
[_tableViewManager addSection:section];
// Add a bool value cell (using UISwitch)
//
[section addItem:[REBoolItem itemWithTitle:@"Switch test" value:YES switchValueChangeHandler:^(REBoolItem *item) {
NSLog(@"Value: %i", item.value);
}]];
Radio (RETableViewOptionsController) Item Example
// Create the manager and assign it to be the delegate and datasource of your UITableView
//
_tableViewManager = [[RETableViewManager alloc] init];
self.tableView.delegate = _tableViewManager;
self.tableView.dataSource = _tableViewManager;
// Add a section
//
RETableViewSection *section = [[RETableViewSection alloc] initWithHeaderTitle:@"Test"];
[_tableViewManager addSection:section];
// Add radio cell (options)
//
__typeof (&*self) __weak weakSelf = self;
RERadioItem *optionItem = [RERadioItem itemWithTitle:@"Radio" value:@"Option 4" selectionHandler:^(RERadioItem *item) {
[weakSelf.tableView deselectRowAtIndexPath:item.indexPath animated:YES];
// Generate sample options
//
NSMutableArray *options = [[NSMutableArray alloc] init];
for (NSInteger i = 1; i < 40; i++)
[options addObject:[NSString stringWithFormat:@"Option %i", i]];
// Present options controller
//
RETableViewOptionsController *optionsController = [[RETableViewOptionsController alloc] initWithItem:item options:options completionHandler:^(RETableViewItem *selectedItem) {
item.value = selectedItem.title;
[weakSelf.tableView reloadRowsAtIndexPaths:@[item.indexPath] withRowAnimation:UITableViewRowAnimationNone];
}];
[weakSelf.navigationController pushViewController:optionsController animated:YES];
}];
[section addItem:optionItem];
Float Item (UISlider) Example
// Create the manager and assign it to be the delegate and datasource of your UITableView
//
_tableViewManager = [[RETableViewManager alloc] init];
self.tableView.delegate = _tableViewManager;
self.tableView.dataSource = _tableViewManager;
// Add a section
//
RETableViewSection *section = [[RETableViewSection alloc] initWithHeaderTitle:@"Test"];
[_tableViewManager addSection:section];
// Add a float item
//
[section addItem:[REFloatItem itemWithTitle:@"Float item" value:0.3 sliderValueChangeHandler:^(REFloatItem *item) {
NSLog(@"Value: %f", item.value);
}]];
Contact
Roman Efimov
License
RETableViewManager is available under the MIT license.
Copyright © 2013 Roman Efimov.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
