我有一个UITableView有很多部分,每个部分只有1行.
我想要做的是,当我点击特定单元格时,应该更改与单元格对应的标题的标题.
我使用-tableView:viewForHeaderInSection设置了节头:
解决方法
我建议实现tableView:titleForHeaderInSection:和tableView:viewForHeaderInSection :(如果两者都实现,那么iOS更喜欢viewForHeaderInSection :).然后让你的tableView实现:viewForHeaderInSection:用标签创建它的视图,并用tableView的结果填充它:titleForHeaderInSection ::
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section UIView *yourHeaderView; UILabel *someLabel; // set up the view + label // if self doesn't implement UITableViewDelegate,you can use tableView.delegate someLabel.text = [self tableView:tableView titleForHeaderInSection:section]; return yourHeaderView; }
现在,当您回答行敲击时,很容易获得相应的标题:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Nsstring *titleForHeader = [self tableView:tableView titleForHeaderInSection:indexPath.section]; }
原文地址:https://www.jb51.cc/iOS/334560.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。