代码之家  ›  专栏  ›  技术社区  ›  Claudio

iPhone开发-定制cel

  •  0
  • Claudio  · 技术社区  · 16 年前

    我试图创建自己的自定义单元格,但由于某种原因,它没有出现。我读了很多例子,代码看起来(至少对我来说)和其他代码一样。我使用接口生成器重新创建了它(我删除了默认视图,添加了TableViewCell,将Identifier=CustomCell,并将标签与ValueLabel连接起来)。

    你能帮我吗?

    事先谢谢。

    //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;
    }
    
    1 回复  |  直到 16 年前
        1
  •  0
  •   Jeff    16 年前

    您的cellforrowatindexpath方法属于表视图控制器吗?那是它所在的地方吗?

    推荐文章