iphone表视图两列自定义视图第二个客户不显示图像(iphone table view two column custom view the second custome not show image)

嗨每个可以告诉我代码发生了什么的人

我想使用表视图实现像图片一样的功能

抱歉:我无法在此处发布图片https://lh6.googleusercontent.com/-ceAzYIdu6EM/UfDJIHT90LI/AAAAAAAAAcE/UQkOwEXIcZE/w506-h281-o/test.png

一个表格单元格有两个自定义视图列,自定义视图单元格代码如下:

#define kTitleFontSize 22.f #define kSummaryFontSize 13.f @implementation FunBoxView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code _backgroundView = [[UIImageView alloc]initWithFrame:CGRectZero]; _backgroundView.contentMode = UIViewContentModeScaleToFill; [self addSubview:_backgroundView]; _heartImageView = [[UIImageView alloc]initWithFrame:CGRectZero]; // _heartImageView.contentMode = UIViewContentModeScaleToFill; [self addSubview:_heartImageView]; _titleLbl = [[UILabel alloc]initWithFrame:CGRectZero]; _titleLbl.backgroundColor = [UIColor clearColor]; _titleLbl.textAlignment = UITextAlignmentCenter; _titleLbl.textColor = [UIColor whiteColor]; _titleLbl.font = [UIFont systemFontOfSize:kTitleFontSize]; [self addSubview:_titleLbl]; _summaryLbl = [[UILabel alloc]initWithFrame:CGRectZero]; _summaryLbl.backgroundColor = [UIColor clearColor]; _summaryLbl.textAlignment = UITextAlignmentCenter; _summaryLbl.textColor = [UIColor whiteColor]; _summaryLbl.font = [UIFont systemFontOfSize:kSummaryFontSize]; [self addSubview:_summaryLbl]; _logoImageView = [[UIImageView alloc]initWithFrame:CGRectZero]; // _logoImageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; [self addSubview:_logoImageView]; } self.contentMode = UIViewContentModeRedraw; return self;

}

-(void)layoutSubviews { CGRect frame = self.frame; CGPoint point = self.center; _backgroundView.frame = CGRectMake(0.f, 0.f, frame.size.width, frame.size.height); _heartImageView.frame = CGRectMake(0.f, 0.f, 320.f / 3 - 8.f, frame.size.height); _heartImageView.center = point; _titleLbl.frame = CGRectMake(0.f, 30.f, frame.size.width,28.f); _summaryLbl.frame = CGRectMake(0.f, _titleLbl.frame.origin.y + _titleLbl.frame.size.height - 6.f, frame.size.width, 25.f); _logoImageView.frame = CGRectMake(point.x - 25.f, _summaryLbl.frame.origin.y + _summaryLbl.frame.size.height - 12.f, 50.f, 50.f);

}

跟随控制器调用表格单元格

cell = [tableView dequeueReusableCellWithIdentifier:secondIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:secondIdentifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; FunBoxView * boxView = [[[FunBoxView alloc]initWithFrame:CGRectMake(0.f, 0.f, cell.frame.size.width * 2 / 3, height)]ah_autorelease]; boxView.tag = HOMETAGBASE ; [boxView addTarget:self action:@selector(buttonClickedAction:) forControlEvents:UIControlEventTouchUpInside]; [cell.contentView addSubview:boxView]; FunBoxView * second = [[FunBoxView alloc]initWithFrame:CGRectMake(cell.frame.size.width * 2 / 3, 0.f, cell.frame.size.width / 3, height)]; second.tag = HOMETAGBASE + 1; [second addTarget:self action:@selector(buttonClickedAction:) forControlEvents:UIControlEventTouchUpInside]; [cell.contentView addSubview:second]; }

但我发现自定义视图图像只显示第一列是显示但下一秒或第三列不会显示图像我不知道发生了什么。

每个人都可以告诉我?

hi every body who can tell me what happened to my code

i want to use the table view implement the function like the picture as followed

sorry: i can't post image here https://lh6.googleusercontent.com/-ceAzYIdu6EM/UfDJIHT90LI/AAAAAAAAAcE/UQkOwEXIcZE/w506-h281-o/test.png

the one table cell have two custom view column the custom view cell code as followed:

#define kTitleFontSize 22.f #define kSummaryFontSize 13.f @implementation FunBoxView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code _backgroundView = [[UIImageView alloc]initWithFrame:CGRectZero]; _backgroundView.contentMode = UIViewContentModeScaleToFill; [self addSubview:_backgroundView]; _heartImageView = [[UIImageView alloc]initWithFrame:CGRectZero]; // _heartImageView.contentMode = UIViewContentModeScaleToFill; [self addSubview:_heartImageView]; _titleLbl = [[UILabel alloc]initWithFrame:CGRectZero]; _titleLbl.backgroundColor = [UIColor clearColor]; _titleLbl.textAlignment = UITextAlignmentCenter; _titleLbl.textColor = [UIColor whiteColor]; _titleLbl.font = [UIFont systemFontOfSize:kTitleFontSize]; [self addSubview:_titleLbl]; _summaryLbl = [[UILabel alloc]initWithFrame:CGRectZero]; _summaryLbl.backgroundColor = [UIColor clearColor]; _summaryLbl.textAlignment = UITextAlignmentCenter; _summaryLbl.textColor = [UIColor whiteColor]; _summaryLbl.font = [UIFont systemFontOfSize:kSummaryFontSize]; [self addSubview:_summaryLbl]; _logoImageView = [[UIImageView alloc]initWithFrame:CGRectZero]; // _logoImageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; [self addSubview:_logoImageView]; } self.contentMode = UIViewContentModeRedraw; return self;

}

-(void)layoutSubviews { CGRect frame = self.frame; CGPoint point = self.center; _backgroundView.frame = CGRectMake(0.f, 0.f, frame.size.width, frame.size.height); _heartImageView.frame = CGRectMake(0.f, 0.f, 320.f / 3 - 8.f, frame.size.height); _heartImageView.center = point; _titleLbl.frame = CGRectMake(0.f, 30.f, frame.size.width,28.f); _summaryLbl.frame = CGRectMake(0.f, _titleLbl.frame.origin.y + _titleLbl.frame.size.height - 6.f, frame.size.width, 25.f); _logoImageView.frame = CGRectMake(point.x - 25.f, _summaryLbl.frame.origin.y + _summaryLbl.frame.size.height - 12.f, 50.f, 50.f);

}

the follow controller invoke table cell

cell = [tableView dequeueReusableCellWithIdentifier:secondIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:secondIdentifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; FunBoxView * boxView = [[[FunBoxView alloc]initWithFrame:CGRectMake(0.f, 0.f, cell.frame.size.width * 2 / 3, height)]ah_autorelease]; boxView.tag = HOMETAGBASE ; [boxView addTarget:self action:@selector(buttonClickedAction:) forControlEvents:UIControlEventTouchUpInside]; [cell.contentView addSubview:boxView]; FunBoxView * second = [[FunBoxView alloc]initWithFrame:CGRectMake(cell.frame.size.width * 2 / 3, 0.f, cell.frame.size.width / 3, height)]; second.tag = HOMETAGBASE + 1; [second addTarget:self action:@selector(buttonClickedAction:) forControlEvents:UIControlEventTouchUpInside]; [cell.contentView addSubview:second]; }

but i found the custom view image show only the first column is show but the next second or third will not show image i don't know what happened .

every body can tell me?

最满意答案

cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:secondIdentifier]; if (cell == nil) { cell.selectionStyle = UITableViewCellSelectionStyleNone; } FunBoxView * boxView = [[[FunBoxView alloc]initWithFrame:CGRectMake(0.f, 0.f, cell.frame.size.width * 2 / 3, height)]ah_autorelease]; boxView.tag = HOMETAGBASE ; [boxView addTarget:self action:@selector(buttonClickedAction:) forControlEvents:UIControlEventTouchUpInside]; [cell.contentView addSubview:boxView]; FunBoxView * second = [[FunBoxView alloc]initWithFrame:CGRectMake(cell.frame.size.width * 2 / 3, 0.f, cell.frame.size.width / 3, height)]; second.tag = HOMETAGBASE + 1; [second addTarget:self action:@selector(buttonClickedAction:) forControlEvents:UIControlEventTouchUpInside]; [cell.contentView addSubview:second]; return cell; cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:secondIdentifier]; if (cell == nil) { cell.selectionStyle = UITableViewCellSelectionStyleNone; } FunBoxView * boxView = [[[FunBoxView alloc]initWithFrame:CGRectMake(0.f, 0.f, cell.frame.size.width * 2 / 3, height)]ah_autorelease]; boxView.tag = HOMETAGBASE ; [boxView addTarget:self action:@selector(buttonClickedAction:) forControlEvents:UIControlEventTouchUpInside]; [cell.contentView addSubview:boxView]; FunBoxView * second = [[FunBoxView alloc]initWithFrame:CGRectMake(cell.frame.size.width * 2 / 3, 0.f, cell.frame.size.width / 3, height)]; second.tag = HOMETAGBASE + 1; [second addTarget:self action:@selector(buttonClickedAction:) forControlEvents:UIControlEventTouchUpInside]; [cell.contentView addSubview:second]; return cell;

更多推荐