jav*_*azo 2 uitableview uiimageview ios
在我的应用程序中,我在左侧有一个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"];
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
你可以这样做
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
您的TableView的委托.
如何更改图像取决于您的实现,但它应该是这样的:
CRMMenuCell *cell = (CRMMenuCell*)[tableView cellForRowAtIndexPath:indexPath];
cell.myImage = newImage;
Run Code Online (Sandbox Code Playgroud)
编辑:尝试以下内容:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CRMMenuCell *cell = (CRMMenuCell*)[tableView cellForRowAtIndexPath:indexPath];
cell.imagenMenu.image = [UIImage imageNamed:@"calendario_gris"];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7786 次 |
| 最近记录: |