在我的应用程序中,我在左侧有一个UITableView作为菜单。当我按下表格的单元格时,右侧的视图会发生变化。 我的“菜单”表有海关单元格,我想在选择此单元格时更改单元格的图像。我怎么能这样做?
CODE:
- (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"];
}
感谢。
答案 0 :(得分:6)
您可以在
中执行此操作- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
表格的委托。
如何更改图像取决于您的实现,但它应该类似于:
CRMMenuCell *cell = (CRMMenuCell*)[tableView cellForRowAtIndexPath:indexPath];
cell.myImage = newImage;
编辑: 请尝试以下方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CRMMenuCell *cell = (CRMMenuCell*)[tableView cellForRowAtIndexPath:indexPath];
cell.imagenMenu.image = [UIImage imageNamed:@"calendario_gris"];
}