gpt4 book ai didi

iphone - 如何在顶部 viewForHeaderInSection 上添加一个 UIButton

转载 作者:行者123 更新时间:2023-11-28 22:50:37 24 4
gpt4 key购买 nike

如何在 viewForHeaderInSection 顶部添加一个按钮。我喜欢在部分标题上方添加一个按钮,可以使用 tableview 滚动。知道怎么做吗?

最佳答案

我在下拉刷新实现中看到的 - 相当骇人听闻的 - 解决方案是简单地将“额外” View 作为 subview 添加到 TableView 中 - 只需确保它使用负 y 偏移进行定位。该偏移量应等于(嗯,而不是 -1 倍)您的 View 高度。代码:

UIView *myViewAboveHeader = // however you create it
CGRect f = myViewAboveHeader.frame;
f.origin.y = -1 * f.size.height;
myViewAboveHeader.frame = f;
[tableView addSubview:myViewAboveHeader];

编辑:您似乎不想要标题 View 及其上方的 View 。在这种情况下,只需在 TableView 委托(delegate)方法中返回的 View 顶部添加一个按钮即可:

- (UIView *)tableView:(UITableView *)tv viewForHeaderInSection:(NSInteger)s
{
UIView *header = ...;
UIButton *btn = // create a button somehow;
[header addSubview:btn];
return header;
}

关于iphone - 如何在顶部 viewForHeaderInSection 上添加一个 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12079420/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com