2010-07-30 2 views
0

Я пытаюсь создать свою собственную пользовательскую ячейку, но по какой-то причине она не появляется. Я читал много примеров, код выглядит (по крайней мере, для меня) равным другим. Я использовал конструктор интерфейса для его воссоздания (я удалил представление по умолчанию, добавил TableViewCell, поместил Identifier = CustomCell и подключил ярлык с помощью valueLabel).IPhone Development - Custom Cel

Может ли помочь мне?

Заранее спасибо.

//CustomCell.h 
#import <UIKit/UIKit.h> 


@interface CustomCell : UITableViewCell { 
    IBOutlet UILabel *valueLabel; 
} 
@property(nonatomic, retain) IBOutlet UILabel *valueLabel; 

@end 

//CustomCell.C 
#import "CustomCell.h" 
@implementation CustomCell 

@synthesize valueLabel; 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 
    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { 
     // Initialization code 
    } 
    return self; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { 

    [super setSelected:selected animated:animated]; 

    // Configure the view for the selected state 
} 


- (void)dealloc { 
    [super dealloc]; 
} 

@end 


//Where I'm trying to use this cell. Here I imported the .h file (#import "CustomCell.h"): 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"CustomCell"; 

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; 

     cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

    } 

    cell.valueLabel.text = @"Any text"; 

    return cell; 
} 

ответ

0

Ваш метод cellForRowAtIndexPath принадлежит контроллеру табличного представления? Это где он находится?

+0

Да, cellForRowAtIndexPath принадлежит к другому файлу (ViewController.C) – Claudio