[英]Get height of Custom UITableViewCell working with different UIStoryboards
在我不使用“ Auto Layout
的项目中,我为不同设备使用了不同的UIStoryboards
。 在UITableViewController
内部,我有两个具有不同高度的不同UITableViewCells
。 我正在尝试在viewDidLoad
以下几行中加载高度
ProfileCell *profilCell =
(ProfileCell *)[self.myTableView dequeueReusableCellWithIdentifier:@"profileCell"];
fProfileHeight = profilCell.frame.size.height;
MenuCell *menuCell =
(MenuCell *)[self.myTableView dequeueReusableCellWithIdentifier:@"menuCell"];
fMenuHeight = menuCell.frame.size.height;
问题是,它与我在UIStoryboard
内部设置的值不匹配。 还设置了CellIdentifier
,并且内容显示正确,我只是无法加载确切的tableRowHeight
。 有人知道我能做什么吗? 我也搜索了这个问题,但是找不到适合我的问题的东西。 我也没有任何笔尖,否则我可以从笔尖文件中加载高度。
之后,您需要将单元格放入Xib接口文件中
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
MenuCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"MenuCell"
owner:nil
options:nil] firstObject];
return cell.frame.size.height;
}
同样,在放入Xib之后,您需要将Nib注册为可重复使用的单元。
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView registerNib:[UINib nibWithNibName:@"MenuCell" bundle:nil]
forCellReuseIdentifier:@"MenuCell"];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.