2
在我的應用程序中,左側的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"];
}
感謝。
很抱歉,但我不能夠找到解決方案,我編輯了這個問題。 – javiazo 2012-08-14 11:19:29
是的,但問題是我的單元格是一個自定義單元格,我的屬性(圖像,標籤等)不在正常的UITableCellView中。 – javiazo 2012-08-14 11:28:29
編輯我的答案。如果您使用不同的單元格,則可能必須在投射和更改圖像之前驗證indexPath。 – user1567896 2012-08-14 11:31:52