EPSCommandCell
是UITableViewCell
的一个子类,具有command
属性
@property (nonatomic) RACCommand *command;
当command
被启用时,单元格的文本颜色设置为当前的自定义颜色(默认为蓝色)。当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;
}
确保当其命令被禁用时,单元格不能被点击
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
EPSCommandCell *cell = (EPSCommandCell *)[tableView cellForRowAtIndexPath:indexPath];
return cell.canExecuteCommand;
}
当单元格被点击时,执行其命令
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
EPSCommandCell *cell = (EPSCommandCell *)[tableView cellForRowAtIndexPath:indexPath];
[cell.command execute:nil];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
EPSCommandCell可通过CocoaPods访问。要安装它,请简单地将以下行添加到您的Podfile中:
pod "EPSCommandCell"
EPSCommandCell在MIT许可证下提供。有关更多信息,请参阅LICENSE文件。