SCArrayOfItemsSection

@interface SCArrayOfItemsSection
    : SCTableViewSection <SCViewControllerDelegate,
                          SCTableViewControllerDelegate> {
  BOOL _isFetchingItems;
  BOOL itemsInSync;
  SCTableViewModel *activeDetailModel;
  NSMutableArray *cellReuseIdentifiers;
  NSObject *tempItem;
  SCDataStore *dataStore;
  SCDataFetchOptions *dataFetchOptions;
  BOOL autoFetchItems;
  UITableViewCellAccessoryType itemsAccessoryType;
  BOOL allowAddingItems;
  BOOL allowDeletingItems;
  BOOL allowMovingItems;
  BOOL allowEditDetailView;
  BOOL allowRowSelection;
  BOOL skipNewItemDetailView;
  BOOL autoSelectNewItemCell;
  NSString *cellIdentifier;
  UIBarButtonItem *addButtonItem;
  SCTableViewCell *placeholderCell;
  SCTableViewCell *addNewItemCell;
  BOOL addNewItemCellExistsInNormalMode;
  BOOL addNewItemCellExistsInEditingMode;
}

This class functions as an SCTableViewModel section that is able to represent an array of any kind of items and automatically generate its cells from these items. The section is also able to handle all end-user interaction with the generated cells, including adding, editing, deleting, and moving the cells. When cells are added or edited, detail views are automatically generated for this purpose. To enable adding cells, the class’ user should set the addButtonItem property of the section to a valid UIBarButtonItem, the section then will automatically add new items when the button is tapped.

When adding new items to the array, the section starts by first asking the model’s data source to provide a new item using its tableViewModel:newItemForArrayOfItemsSectionAtIndex: SCTableViewModelDataSource protocol method.

This class is an abstract base class. Subclasses of this class must override the buildDetailTableModel method. This method should return a model for the detail view to display.

Warning

This is an abstract base class, you should never make any direct instances of it.

See

SCArrayOfStringsSection, SCArrayOfObjectsSection.

Creation and Initialization

  • Allocates and returns an initialized ‘SCArrayOfItemsSection’ given a data store.

    Declaration

    Objective-C

    + (instancetype)sectionWithHeaderTitle:(NSString *)sectionHeaderTitle
                                 dataStore:(SCDataStore *)store;

    Parameters

    sectionHeaderTitle

    A header title for the section.

    store

    The data store containing the section’s items.

  • Returns an initialized ‘SCArrayOfItemsSection’ given a data store.

    Declaration

    Objective-C

    - (instancetype)initWithHeaderTitle:(NSString *)sectionHeaderTitle
                              dataStore:(SCDataStore *)store;

    Parameters

    sectionHeaderTitle

    A header title for the section.

    store

    The data store containing the section’s items.

Configuration

  • The data store that’s used to store and fetch the section’s items.

    Declaration

    Objective-C

    @property (nonatomic, strong) SCDataStore *dataStore;
  • The options used to fetch the section’s items from dataStore.

    Declaration

    Objective-C

    @property (nonatomic, strong) SCDataFetchOptions *dataFetchOptions;
  • The items fetched from dataStore.

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSArray *items;
  • Set to FALSE to disable the section from automatically fetching its items from dataStore. Default: TRUE.

    Declaration

    Objective-C

    @property (nonatomic) BOOL autoFetchItems;
  • This property is TRUE when the section is in a state of fetching its items from their dataStore.

    Declaration

    Objective-C

    @property (nonatomic, readonly) BOOL isFetchingItems;
  • The accessory type of the generated cells.

    Declaration

    Objective-C

    @property (nonatomic) UITableViewCellAccessoryType itemsAccessoryType;
  • Automatically hides section if it has no items. Default: FALSE.

    Declaration

    Objective-C

    @property (nonatomic) BOOL hideWhenEmpty;
  • Allows/disables adding new cells/items to the items array. Default: TRUE.

    Declaration

    Objective-C

    @property (nonatomic) BOOL allowAddingItems;
  • Allows/disables deleting new cells/items from the items array. Default: TRUE.

    Declaration

    Objective-C

    @property (nonatomic) BOOL allowDeletingItems;
  • Allows/disables moving cells/items from one row to another. Default: TRUE.

    Declaration

    Objective-C

    @property (nonatomic) BOOL allowMovingItems;
  • Allows/disables a detail view for editing items’ values. Default: TRUE.

    Detail views are automatically generated for editing new items. You can control wether the view appears as a modal view or gets pushed to the navigation stack using the detailViewModal property. Modal views have the added feature of giving the end user a Cancel and Done buttons. The Cancel button cancels all user’s actions, while the Done button commits them. Also, if the cell’s validation is enabled, the Done button will remain disabled until all cells’ values are valid.

    Declaration

    Objective-C

    @property (nonatomic) BOOL allowEditDetailView;
  • Allows/disables row selection. Default: TRUE.

    Declaration

    Objective-C

    @property (nonatomic) BOOL allowRowSelection;
  • Set to TRUE to directly add the new item without displaying a detail view. This is useful in situations where the item details will be filled in programmatically by implementing the SCTableViewModelDelegate ‘tableViewModel:itemAddedForSectionAtIndexPath:item:’ method. Default: FALSE.

    Declaration

    Objective-C

    @property (nonatomic) BOOL skipNewItemDetailView;
  • Allows/disables automatic cell selection of newly created items. Default: TRUE.

    Declaration

    Objective-C

    @property (nonatomic) BOOL autoSelectNewItemCell;
  • Automatically commits any changes to detail model. Set to FALSE if you’re planning to commit the changes yourself, or if detail model is in read-only mode. Default: TRUE.

    Declaration

    Objective-C

    @property (nonatomic) BOOL autoCommitDetailModelChanges;
  • Set this property to a valid UIBarButtonItem. When addButtonItem is tapped and allowAddingItems is TRUE, a detail view is automatically generated for the user to enter the new items properties. If the properties are commited, a new item is added to the array.

    See

    addNewItemCell

    Declaration

    Objective-C

    @property (nonatomic, strong) UIBarButtonItem *addButtonItem;

Configuring Special Cells

Manual Event Control

  • User can call this method to dispatch an AddNewItem event, the same event dispached when the end-user taps addButtonItem.

    Declaration

    Objective-C

    - (void)dispatchEventAddNewItem;
  • User can call this method to dispatch a SelectRow event, the same event dispached when the end-user selects a cell.

    Declaration

    Objective-C

    - (void)dispatchEventSelectRowAtIndexPath:(NSIndexPath *)indexPath;
  • User can call this method to dispatch a RemoveRow event, the same event dispached when the end-user taps the delete button on a cell.

    Declaration

    Objective-C

    - (void)dispatchEventRemoveRowAtIndexPath:(NSIndexPath *)indexPath;

Internal Properties & Methods (should only be used by the framework or when subclassing)