的UITableViewCell大小不合适
问题描述:
创建的.xib:的UITableViewCell大小不合适
设置类:
这是怎么显示:
这是我的方式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高度:
补充说:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 150;
}
也练就了我的高度,但仍然没有背景色。有点让我觉得我没有正确设置别的东西。
答
你可以从你的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];
}
你在UITableView的在IB设置单元格的高度?或者在tableView:heightForRowAtIndexPath委托方法中? – 2013-05-13 21:45:01