获取分组 UITableView 中单元格的宽度以设置节标题宽度 [英] Getting width of a cell in a grouped UITableView for setting section header width

查看:58
本文介绍了获取分组 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);

这篇关于获取分组 UITableView 中单元格的宽度以设置节标题宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆