2011-07-31 3 views
1

J'ai créé mon UITableViewCell programatically (pas xib) et voici comment je l'ai dans mon code:UITableViewCell ne pas appeler initWithFrame

- (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.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; 
} 

Le problème est que je ne vois pas appeler le initWithFrame appelé, pourquoi est-ce? Et donc ce que je vois est juste cellules vides ...

Répondre

7

initWithFrame n'est pas appelé parce que vous appelez

initWithFrame: reuseIdentifier:

remplacer

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

avec

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

Aussi s'il vous plaît gardez à l'esprit que initWithFrame: reuseIdentifier est une méthode obsolète et vous devez utiliser initWithStyle: reuseIdentifier à la place.

+0

alors comment résoudre ce problème? – adit

+0

a modifié ma réponse –

Questions connexes