1

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

我想使用表格视图实现如下图所示的功能

抱歉:我无法在此处发布图片 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];
    }

但我发现自定义视图图像仅显示第一列,但接下来的第二或第三列不会显示图像,我不知道发生了什么。

每个人都可以告诉我吗?

4

1 回答 1

0
    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;
于 2013-07-25T07:04:53.830 回答