好的,我在想的是,标题、Events、Overhead 和 Friends 将是带有 @ 的自定义 UIView 987654322@ 用于背景,UILabel 用于标题,UIButton 用于扩展。所以基本上
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
返回您拥有的标题的计数。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
为每个标题返回UIView。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
拥有该标题中的行数。 您可能需要为此维护一个数组。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
具有单元格项目的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
最初所有部分都应该为 0(零),当用户点击展开时,它应该相对于该部分内的行数 * 单元格高度增加。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
您可能需要一些好的逻辑来设置所有行以进行扩展
您的扩展按钮操作类似于,
- (void) expandSection:(UIButton *)sender;
您可以使用 sender.tag 确定要扩展的部分,所以不要忘记正确添加标签。您可能需要在.h 文件中使用int 来存储当前部分,并且可以在- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 数据源方法中使用。