开发者

UITableViewCell not calling initWithFrame

I created my UITableViewCell programatically (no xib) and here's how I have it in my code:

- (id) initWithFrame: (CGRect)frame {
    self = [super initWithFrame: frame];
    if (self) {
        NSLog(@"CALLING INIT WITH FRAME");

        self.like_img = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 75, 30, 30)] autorelease];
        [self.contentView addSubview: self.like_img];

        self.comment_img = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 110, 30, 30)] autorelease];
        [self.contentView addSubview: self.comment_img];

        self.type_img = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 40, 30, 30)] autorelease];
        [self.contentView addSubview:self.type_img];

        self.avatar = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 30, 30)] autorelease];
        [self.contentView addSubview:self.avatar];

        self.post = [[[UITextView alloc] initWithFrame:CGRectMake(40, 40, 650, 100)] autorelease];
        [self.contentView addSubview:self.post];

        self.post_title= [[[UILabel alloc] initWithFrame:CGRectMake(40, 20, 650, 50)] autorelease];
        [self.contentView addSubview:self.post_title];

        self.开发者_JS百科post_detail = [[[UILabel alloc] initWithFrame:CGRectMake(40, 10, 650, 20)] autorelease];
        [self.contentView addSubview:self.post_detail];

    }

    NSLog(@"NOT MY SELF");
    return self;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"FTPostCell";

    FTPostCell *cell = (FTPostCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSLog(@"INITIALIZING CELL");
        cell = [[[FTPostCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

  //snip some code here
  return cell;
}

The issue is that I don't see it calling the initWithFrame being called, why is this? And therefore what I am seeing is just empty cells...


initWithFrame is not called because you call

initWithFrame: reuseIdentifier:

replace

- (id) initWithFrame: (CGRect)frame {
    self = [super initWithFrame: frame];

with

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithFrame: frame reuseIdentifier:reuseIdentifier];

Also please mind that initWithFrame:reuseIdentifier is a deprecated method and you should use initWithStyle:reuseIdentifier instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜