Getting width of a cell in a grouped UITableView f

2019-05-31 13:43发布

Header says it all really I just need to get at the cell width of the table so I can set my section header width to be the same + a few pixels. Here is semi pseudo-code for my problem.

CustomHeaderView *headerView = [[CustomHeaderView alloc] init];
headerView.frame.width = [tableView getCellFrameWidth] + 10;

Been struggling with this all day. Getting at the width of the cells in a grouped tableview seems like it should be a trivial operation, but for some reason is not. Having said that I'm a complete beginner in IOS programming so if some of you veterans out there could explain to me why this is not trivial that would be awesome.

3条回答
爷、活的狠高调
2楼-- · 2019-05-31 14:02

The Width of grouped UITableViewCell depends on table width and calculates as

table.frame.size.width/16.0*14.0
查看更多
再贱就再见
3楼-- · 2019-05-31 14:03
  UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section]];

CGRect rect = cell.frame;

NSLog(@"Cell width = %f",rect.size.width);
查看更多
手持菜刀,她持情操
4楼-- · 2019-05-31 14:23

These things are always subject to change, but the width of a UITableViewCell in a grouped UITableView is 300.0 points and has been since iPhone OS 1.0.

查看更多
登录 后发表回答