2010-07-30 62 views
0

我試圖創建自己的自定義單元,但由於某種原因,它沒有出現。我讀了很多示例,代碼看起來像(至少對我來說)與其他人相同。我使用界面生成器來重新創建它(我刪除了默認視圖,添加一個TableViewCell,把Identifier = CustomCell,並用valueLabel連接Label)。iPhone開發 - 自定義Cel

可以comeone幫我嗎?

在此先感謝。

//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 2010-07-30 03:26:04