Skip to content

AKAFormTableViewController

Michael edited this page Apr 28, 2016 · 2 revisions

Please note that this controller has been developed quite early when a lot of functionality of Beacon was not yet there. It works quite well but it doesn't fit well into the rest of the framework. We will most likely replace this with something more in line with beacon's architecture, but probably not anytime soon.

Static table views offer some very handy features which make them very attractive as a layout device for Forms:

  • Cells are static, you can connect views to outlets and cells are not being reused and keep their state.
  • Table views offer good layout features for forms.
  • You don't have to implement your own data source, since the table view is static, you can use it just as you would use a plain view controller but still have all the advantages a table view offers.

AKAFormTableViewController adds support for bindings to plain UITableViewControllers. If you use it, you can define binding expressions in cells which will use the controller as view model.

Additionally, the controller offers some nice features:

Features

Dynamic Cells

One of the disadvantages of using static table views is that they are static and you cannot mix dynamic prototype and static table views. Not until now at least.

If you're using AKAFormTableViewController, you can actually mix them (kind of). If you set the type of a cell to AKADynamicPlaceholderTableViewCell and set the collectionBinding property (to a key path referencing an array), the placeholder cell will be used as prototype and will be replaced with instances for items of the source data array.

You can use placeholder cells much the same way that you would use storyboard prototype cells.

Of course, whenever the source array changes, the table view will be updated (insert/delete).

Hiding Cells and Groups of Cells

Beacon adds a property controlTags to UITableViewCell, which can be used to tag cells.

AKAFormViewController provides three methods rowControlsTaggedWith:, hideRowControls:withRowAnimation and unhideRowControls:withRowAnimation that can be used to hide and show groups of cells. Here an example of a view model property serverScannerEnabled that switches between a set of cells implementing a network scanner and another set of cells providing text fields to manually enter information:

- (void)setServerScannerEnabled:(BOOL)serverScannerEnabled
{
    if (serverScannerEnabled != _serverScannerEnabled)
    {
        _serverScannerEnabled = serverScannerEnabled;
        if (serverScannerEnabled)
        {
            self.serverScanResults = nil;
            [self.serverScanner reset];
            self.serverScanner.autostart = YES;
        }
        else
        {
            self.serverScanResults = nil;
        }

        NSArray* serverEditorControls = [self rowControlsTaggedWith:@"serverEditor"];
        NSArray* serverScannerControls = [self rowControlsTaggedWith:@"serverScanner"];
        if (serverScannerEnabled)
        {
            [self hideRowControls:serverEditorControls withRowAnimation:UITableViewRowAnimationLeft];
            [self unhideRowControls:serverScannerControls withRowAnimation:UITableViewRowAnimationRight];
        }
        else
        {
            [self hideRowControls:serverScannerControls withRowAnimation:UITableViewRowAnimationRight];
            [self unhideRowControls:serverEditorControls withRowAnimation:UITableViewRowAnimationLeft];
        }
    }
}

Composing Table Views

...