我已经创建了一个带有 xib 的 uiviewcontroller 以添加到 uitableview 单元格中。这是代码。
@interface CustomeCellHome : UIViewController{
IBOutlet UIImageView *imgViewBack;
// will have number of labels and imageviews.
}
@property (nonatomic, retain) UIImageView *imgViewBack;
@implementation CustomeCellHome
@synthesize imgViewBack;
所有这些 IBOutlet 都连接到 xib。
现在我将其添加到我的 uitableview 单元格中。这是代码。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 150;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
// }
CustomeCellHome *objCell = [[CustomeCellHome alloc] init];
[objCell.view setTag:indexPath.row];
[cell.contentView addSubview:objCell.view];
objCell.imgViewBack.image = [UIImage imageNamed:@"unsel.png"];
[objCell release];
return cell;
}
现在我想在选择行时更改这个 imgViewBack 图像。这是代码。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CustomeCellHome *objCCell = [[CustomeCellHome alloc] init];
objCCell.view = [cell viewWithTag:indexPath.row];
objCCell.imgViewBack.image = [UIImage imageNamed:@"sel.png"];
}
但我的 imgViewBack 并没有改变它的形象。不明白这有什么问题。有什么建议吗?任何建议将不胜感激。