2013-05-13 78 views
0

創建的.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

回答

1

你可以從你的UITableViewDelegate設置的tableView行的高度:

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

檢查Interface Builder中父級UITableView的單元格高度。該值必須是原始(較小)值。嘗試將此值設置爲您要設置的高度。

2

不幸的是,你不能設置在廈門國際銀行的背景顏色爲普通表視圖樣式(它的工作對分組表的風格)。你必須在代碼中設置的顏色在的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