你必须创建单元状态e.g一些基础模型:
@property NSString *modelState = @"red"; // this is fast hint, but it can be a enum with states.
所有的细胞都会有自来水后一个冠军。
...其他控制器代码...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.restaurantTable dequeueReusableCellWithIdentifier:@"cell_ID"];
// cell customization method
[self customizeCell:cell accordingToStateStr:modelState];
return cell;
}
...其他控制器代码...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
// Set other state for cell
self.modelState = @"red";
[tableView reloadData];
}
- (void)customizeCell:(UITableViewCell*)cell accordingToStateStr:(NSString *)str {
if ([str isEqualToString:@"red"]) {
cell.backgroundColor = [UIColor redColor];
cell.textLabel.textColor = [UIColor redColor];
cell.textLabel.text = @"Title";
} else if(...) {
//Other options..
}
}
[的tableView reloadData]; - 将再次触发“cellForRow”方法,您的表格将根据新模型重新绘制。
你可以使用单元状态emuns代替NSString对象(这只是你的脚手架)。
这是我做不成功(检查示例代码)... –
@TomKortney仔细阅读我的代码。我直接发送消息给'tableView',而不是'self'。 – liushuaikobe
据我所见,这个答案是最简单的答案。谢谢! –