Hi Adam,
You actually need to use only one of these methods, not both. Let me explain this in more detail.
For your convenience, Sensible TableView has two parallel delegate systems for you to work with, with a lot of common shared methods. One delegate system (protocol) is for the model itself (SCTableViewModelDelegate), while the other is for the model's cells (SCTableViewCellDelegate). While SCTableViewModelDelegate is sufficient to cover all your needs, sometimes the cell you want to customize is barried deep within the automatically generated detail views, and setting up its model to receive your delegate method may be a bit challenging. Here is where the class definition's uiElementDelegate comes to the rescue, allowing you to set the delegate property of individual cells.
So to be more specific, you basically have two choices when it comes to cell customization:
1- Set the model's delegate property to "self" (which is done for you automatically as soon as the model is created) and use one or more of the SCTableViewModelDelegate methods. This is mostly used for cells that belong to the root model. This method can also be perfectly used for detail models, provided that you assign the detail models' delegate property to "self". The challenge then would be for you to know which model is actually calling your delegate method. Most of our customers solve this by assigning a tag to each model as soon as it's created. Here is a code sample that illustrates what I mean:
// All these methods belong to the SCTableViewModelDelegate protocol
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
detailViewWillAppearForRowAtIndexPath:(NSIndexPath *)indexPath
withDetailTableViewModel:(SCTableViewModel *)detailTableViewModel
{
// Set a tag to uniquely identify the detail model. What I am doing here is setting
// a tag that is equivalent to the model's level in the hierarchy.
detailTableViewModel.tag = tableViewModel.tag + 1;
// Make sure to set the delegate property of the detail model, otherwise it won't
// be calling any of your delegate methods
detailTableViewModel.delegate = self;
}
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
willConfigureCell:(SCTableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (tableViewModel.tag)
{
case 0: // root model
// customizations relevant to root model
break;
case 1: // detail model at level 1
// customizations relevant to detail model at level 1
break;
// etc.
}
}
2- Set the individual cell's delegate to "self". This saves you from worrying about which model does the cell belong to (like I did in the code sample), and will have the cell directly call its delegate method. If your cells are automatically generated via a class definition, the class definition will do two thing:
a. Each cell's tag with be set to its index within the class definition.
b. If you set the class definition's uiElementDelegate, each cell will automatically have its delegate property assigned to the value of uiElementDelegate.
With this setup, you are able to use SCTableViewCellDelegate methods like this:
- (void)willConfigureCell:(SCTableViewCell *)cell
{
// customize the individual cell here
}
Please tell me if this needs more explanation