在我的应用程序中,左侧有一个 UITableView 作为菜单。当我按下表格的一个单元格时,右侧的视图会发生变化。我的“菜单”表有自定义单元格,我想在选中此单元格时更改单元格的图像。我怎样才能做到这一点?
代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"MenuCell";
CRMMenuCell *cell = (CRMMenuCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell){
NSArray * topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CRMMenuCell" owner:nil options:nil];
for (id currentObjetc in topLevelObjects){
if ([currentObjetc isKindOfClass:[CRMMenuCell class]]){
cell = (CRMMenuCell *)currentObjetc;
break;
}
}
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (indexPath.row == 0)
{
cell.labelMenu.text = NSLocalizedString(@"calendarioKey", @"");
cell.imagenMenu.image = [UIImage imageNamed:@"calendario_gris"];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"MenuCell";
CRMMenuCell *cell = (CRMMenuCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell){
NSArray * topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CRMMenuCell" owner:nil options:nil];
for (id currentObjetc in topLevelObjects){
if ([currentObjetc isKindOfClass:[CRMMenuCell class]]){
cell = (CRMMenuCell *)currentObjetc;
break;
}
}
}
if (indexPath.row == 0)
{
cell.imagenMenu.image = [UIImage imageNamed:@"calendario_rojo"];
}
谢谢。