【问题标题】:How to bring a certain cell to front如何将某个单元格放在前面
【发布时间】:2014-04-10 10:07:32
【问题描述】:

在我的表格视图中,我有三个部分,其中第一部分包含图像单元格,第二部分包含段控制单元格,第三部分包含一些标签单元格。 我正在做的是当用户向上滚动表格视图时,所有内容都会向上滚动,但段控制单元格的位置将固定在屏幕的上边缘。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSIndexPath *indexPathOfCurrentHeaderCell =  [NSIndexPath indexPathForRow:0 inSection:0]          ;
UITableViewCell *headerCell = [self.tableView cellForRowAtIndexPath:indexPathOfCurrentHeaderCell];
if (headerCell.frame.origin.y < self.tableView.contentOffset.y)
{
    self.cellHead.hidden = NO;
    self.cellHead.frame = CGRectMake(0, self.tableView.contentOffset.y, self.cellHead.frame.size.width, self.cellHead.frame.size.height);        
}
[self.tableView bringSubviewToFront:self.cellHead];
}

但是函数 bringSubviewToFront: 在这里似乎不起作用(第二部分将被第三部分覆盖)。我认为这是因为单元格不是表格视图的子视图。 想把段控单元拉到最前面怎么办?

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:

    您应该在表格视图中将段控件添加为标题而不是单元格,使用

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    

    那么,您将有 2 个部分,

    1. image cell
    2. segment control as header, labels as the cells
    

    【讨论】:

    • 嗨,Lewen,谢谢你的回复。但它也不起作用。滚动时,头部视图将向上移出视图。
    猜你喜欢
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多