The iOS framework that grows only as fast as its documentation
NIRadioGroup Class Reference

Overview

A general-purpose radio group.

This group object manages radio-style selection of objects. Only one object may be selected at a time.

Due to the general-purpose nature of this object, it can be used with UITableViews or any other view that has sets of objects being displayed. This object can insert itself into a UITableViewDelegate call chain to minimize the amount of code that needs to be written in your controller.

If you add a NIRadioGroup object to a NITableViewModel, it will show a cell that displays the current radio group selection. This cell is also tappable. Tapping this cell will push a controller onto the navigation stack that presents the radio group options for the user to select. The radio group delegate is notified immediately when a selection is made and the tapped cell is also updated to reflect the new selection.

Inheritance diagram for NIRadioGroup:
<NICellObject>

Tasks

(Class) - cellClass
 
(UITableViewCellStyle) - cellStyle
 
Selection
NSInteger selectedIdentifier property
 
(BOOL) - hasSelection
 
(void) - clearSelection
 
Forwarding
UITableViewCellSelectionStyle tableViewCellSelectionStyle property
 
NSString * cellTitle property
 
NSString * controllerTitle property
 
(id< UITableViewDelegate >) - forwardingTo:
 
(void) - removeForwarding:
 
(NSArray *) - allObjects
 
Creating Radio Groups
(id) - initWithController:
 
Mapping Objects
(id) - mapObject:toIdentifier:
 
Object State
(BOOL) - isObjectInRadioGroup:
 
(BOOL) - isObjectSelected:
 
(NSInteger) - identifierForObject:
 

Method Documentation

selectedIdentifier

The currently selected identifier if one is selected, otherwise returns NSIntegerMin.

@property (nonatomic) NSInteger selectedIdentifier;

tableViewCellSelectionStyle

The cell selection style that will be applied to the cell when it is displayed using delegate forwarding.

@property (nonatomic) UITableViewCellSelectionStyle tableViewCellSelectionStyle;
Discussion

By default this is UITableViewCellSelectionStyleBlue.

cellTitle

The title of the cell that is displayed for a radio group in a UITableView.

@property (nonatomic, copy) NSString* cellTitle;

controllerTitle

The title of the controller that shows the sub radio group selection.

@property (nonatomic, copy) NSString* controllerTitle;

initWithController:

Initializes a newly allocated radio group object with the given controller.

- (id)initWithController:(UIViewController *)controller;
Discussion

This is the designated initializer.

The given controller is stored as a weak reference internally.

Parameters
controllerThe controller that will be used when this object is used as a sub radio group.

mapObject:toIdentifier:

Maps the given object to the given identifier.

- (id)mapObject:(id)object toIdentifier:(NSInteger)identifier;
Discussion

The identifier will be used in all subsequent operations and is a means of abstracting away the objects. The identifier range does not have to be sequential. The only reserved value is NSIntegerMin, which is used to signify that no selection exists.

You can NOT map the same object to multiple identifiers. Attempts to do so fill fire a debug assertion and will not map the new object in the radio group.

Parameters
objectThe object to map to the identifier.
identifierThe identifier that will represent the object.
Returns
The object that was mapped.

hasSelection

Whether or not a selection has been made.

- (BOOL)hasSelection;

clearSelection

Removes the selection from this cell group.

- (void)clearSelection;

isObjectInRadioGroup:

Returns YES if the given object is in this radio group.

- (BOOL)isObjectInRadioGroup:(id)object;

isObjectSelected:

Returns YES if the given object is selected.

- (BOOL)isObjectSelected:(id)object;
Discussion

This method should only be called after verifying that the object is contained within the radio group with isObjectInRadioGroup:.

identifierForObject:

Returns the mapped identifier for this object.

- (NSInteger)identifierForObject:(id)object;
Discussion

This method should only be called after verifying that the object is contained within the radio group with isObjectInRadioGroup:.

forwardingTo:

Sets the delegate that table view methods should be forwarded to.

- (id<UITableViewDelegate>)forwardingTo:(id<UITableViewDelegate>)forwardDelegate;
Discussion

This method allows you to insert the radio group into the call chain for the table view's delegate methods.

Example:

// Let the radio group handle delegate methods and then forward them to whatever delegate was
// already assigned.
self.tableView.delegate = [self.radioGroup forwardingTo:self.tableView.delegate];
Parameters
forwardDelegateThe delegate to forward invocations to.
Returns
self so that this method can be chained.

removeForwarding:

Removes the delegate from the forwarding chain.

- (void)removeForwarding:(id<UITableViewDelegate>)forwardDelegate;
Discussion

If a forwared delegate is about to be released but this object may live on, you must remove the forwarding in order to avoid invalid access errors at runtime.

Parameters
forwardDelegateThe delegate to stop forwarding invocations to.

allObjects

An array of mapped objects in this radio group, ordered in the same order they were mapped.

- (NSArray*)allObjects;
Discussion

This is used primarily by NIRadioGroupController to display the radio group options.

cellClass

The class of cell to be created when this object is passed to the cell factory.

- (Class)cellClass;
Discussion

cellStyle

The style of UITableViewCell to be used when initializing the cell for the first time.

- (UITableViewCellStyle)cellStyle;
Discussion