获取分组 UITableView 中单元格的宽度以设置节标题宽度

获取分组 UITableView 中单元格的宽度以设置节标题宽度

问题描述:

标题说明了一切我只需要获得表格的单元格宽度,这样我就可以将我的部分标题宽度设置为相同+几个像素.这是我的问题的半伪代码.

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;

整天都在为此苦苦挣扎.获取分组 tableview 中单元格的宽度似乎应该是一个微不足道的操作,但由于某种原因不是.话虽如此,我是 IOS 编程的完全初学者,所以如果你们中的一些老手可以向我解释为什么这不是微不足道的,那会很棒.

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.

  UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section]];

CGRect rect = cell.frame;

NSLog(@"Cell width = %f",rect.size.width);