我在 IB 中创建了一个自定义 UITableViewCell,将其链接到 Root View Controller 的属性,并在 CellForRowAtIndexPath 中进行设置。但是我绘制的单元格的高度与我在 IB 中设置的不匹配,建议?这是一些屏幕截图和代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *AddressCellIdentifier = @"AddressCellIdent";
UITableViewCell *thisCell = [tableView dequeueReusableCellWithIdentifier:AddressCellIdentifier];
if (thisCell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"AddressCell" owner:self options:nil];
thisCell = addressCell;
self.addressCell = nil;
}
return thisCell ;
}
addressCell 是一个@property (nonatomic, assign) IBOutlet UITableViewCell *addressCell;,并且在 IB 中链接到文件的所有者( TableView Controller )。
我正在使用 Apple 的 TableView 编程指南中的示例。
最佳答案
IB中有两个地方需要设置行高。首先是单元格本身的自定义行高。单击要调整大小的单元格,然后单击右侧实用程序窗口中的大小检查器(标尺)。在“表格 View 单元格”部分下方的顶部设置行高。单击自定义复选框。
然后在左侧的“文档大纲”窗口中单击“ TableView ”。返回右侧实用程序窗口中的大小检查器,将整个表格的行高设置为所需的高度。
使用此实现,您无需向 tableviewcontroller 添加任何代码。
关于iphone - 自定义 Nib UITableViewCell 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4611126/