EPSCommandCell
is a subclass of UITableViewCell
which has a command
property:
@property (nonatomic) RACCommand *command;
When command
is enabled, the cell’s text color is set to the current tint color (blue by default). When command
is disabled, the cell’s text is gray.
Set up the cell with a command:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
EPSCommandCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = "Some Text";
cell.command = self.someCommand;
return cell;
}
Make sure the cell can’t be tapped when its command is disabled:
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
EPSCommandCell *cell = (EPSCommandCell *)[tableView cellForRowAtIndexPath:indexPath];
return cell.canExecuteCommand;
}
When the cell is tapped, execute its command:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
EPSCommandCell *cell = (EPSCommandCell *)[tableView cellForRowAtIndexPath:indexPath];
[cell.command execute:nil];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
EPSCommandCell is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "EPSCommandCell"
EPSCommandCell is available under the MIT license. See the LICENSE file for more info.