我正在使用heightForRowAtIndexPath:方法返回100來設置單元格的高度。 但是在cellForRowAtIndexPath方法中,單元格的框架高度始終爲44px。UITableViewCell框架高度總是44px
以下是我的代碼。
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
- (int) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
[cell setBackgroundColor:[UIColor redColor]];
[cell.contentView setBackgroundColor:[UIColor redColor]];
cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row];
NSLog(@"%f %f", cell.frame.size.height, cell.contentView.frame.size.height);
return cell;
}
NSLog語句打印「44px 44px」。
我能夠使用此語句而分配細胞
CGFloat height = [tableView heightForRowAtIndexPath:indexPath];
您是否在Interface Builder中有一個ID爲「Cell」且高度爲44的原型單元? –
默認的UITableViewCell是44.繪圖期間應用100px的高度。 –