的UITableViewCell大小不合适

问题描述:

创建的.xib:的UITableViewCell大小不合适

enter image description here

设置类:

enter image description here

这是怎么显示:

enter image description here

这是我的方式OAD细胞:

@implementation FieldInfoTableViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UINib *cellNib = [UINib nibWithNibName:@"FieldInfoCell" bundle:nil]; 

    [self.tableView registerNib:cellNib forCellReuseIdentifier:FieldInfoCellIndentifier]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.section == 0) { 
     FieldInfoCell *fieldCell = [tableView dequeueReusableCellWithIdentifier:FieldInfoCellIndentifier forIndexPath:indexPath]; 

     fieldCell.fieldNameLabel.text = self.boundarier.name; 

     return fieldCell; 
    } 

    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    return cell; 
} 

FielcInfoCell:

@interface FieldInfoCell : UITableViewCell 

@property (strong, nonatomic) IBOutlet UILabel *fieldNameLabel; 

@end 

@implementation FieldInfoCell 

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

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
    [super setSelected:selected animated:animated]; 

    // Configure the view for the selected state 
} 

@end 

标签被重命名,但细胞的大小和背景颜色都未被设置。

编辑:

我设置IB高度:

enter image description here

补充说:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 150; 
} 

也练就了我的高度,但仍然没有背景色。有点让我觉得我没有正确设置别的东西。

+1

你在UITableView的在IB设置单元格的高度?或者在tableView:heightForRowAtIndexPath委托方法中? – 2013-05-13 21:45:01

你可以从你的UITableViewDelegate设置的tableView行的高度:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
     return YOUR_HEIGHT; 
    } 

检查Interface Builder中父级UITableView的单元格高度。该值必须是原始(较小)值。尝试将此值设置为您要设置的高度。

不幸的是,你不能设置在厦门国际银行的背景颜色为普通表视图样式(它的工作对分组表的风格)。你必须在代码中设置的颜色在的tableView:willDisplayCell:forRowAtIndexPath:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (indexPath.section == 0) 
     cell.backgroundColor = [UIColor colorWithRed:173/255.0 green:75/255.0 blue:33/255.0 alpha:1]; 
} 
+0

@ Log139,嗯...,它为我做了。你看到什么颜色?白色? – rdelmar 2013-05-13 22:34:02

+0

Sry,在我意识到它在'tableView:willDisplayCell:ForRowAtIndexPath:'方法之前,我对它进行了评论。这确实有用,谢谢。 – Padin215 2013-05-13 22:36:34