我已经创建了一个uiviewcontroller与xib添加到uitableview单元格中。这里是代码。当custome视图添加到单元格时更改单元格内容视图
@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没有改变自己的形象。不要弄错这个问题。对此有何建议?任何建议将不胜感激。
什么是崩溃错误? – iremk 2012-07-16 07:01:46
和你需要做的我猜, CustomeCellHome * objCCell = [[CustomeCellHome alloc] init]; ,因为它没有初始化.. – iremk 2012-07-16 07:02:40
感谢您回答iremk,我已经试过这个。现在它不会崩溃,但不会改变imageview的图像。我更新了代码。 – 2012-07-16 07:06:28