菜鸟教程小白 发表于 2022-12-11 17:19:40

ios - 带有 HeaderView 的 UITableView 不滚动


                                            <p><p>我正在尝试创建一个屏幕,其中包含一些 <code>UIElements</code> 和一个 <code>UITableView</code>。
为了使所有内容都可以滚动,我实现了一个 <code>UITableView</code> 和一个包含 <code>UIElements</code> 的 <code>tableHeaderView</code>。</p>

<p>现在 View 无法正确滚动以显示所有 <code>UITableViewCells</code>。</p>

<p>这是我到目前为止所遵循的步骤:</p>

<ol>
<li>以编程方式创建的 <code>UIView</code> 是 <code>Subviews</code></li>
<li>设置自定义<code>UIView</code>为<code>table.tableHeaderView</code></li>
<li>加载了<code>数据</code>。</li>
</ol>

<p>我到底错过了什么?</p>

<p><strong>编辑:三个步骤的代码</strong></p>

<p>1,2.<br/>
      let bounds = UIScreen.mainScreen().bounds</p>

<pre><code>    imageSliderVC = TNImageSliderViewController()
    imageSliderVC.view.frame = CGRectMake(0, 0, bounds.width, bounds.width)


    layerView = UIView(frame: CGRectMake(0, 0, bounds.width, bounds.width))
    layerView.alpha = 0.25
    layerView.backgroundColor = UIColor.blackColor()

    noButton = constructNopeButton()
    yesButton = constructLikedButton()
    buttonOptionsApply()

    nameLbl = UILabel(frame: CGRectMake(20, layerView.frame.maxY + 20, bounds.width-40, 20))
    nameLbl.makeNameLabelFormat()
    hashtagLbl = UILabel(frame: CGRectMake(20, nameLbl.frame.maxY + 5, bounds.width-40, layerView.frame.width/3.66))
    hashtagLbl.makeHashtagFormat()

    seperatorLbl = UILabel(frame: CGRectMake(20, hashtagLbl.frame.maxY + 15, bounds.width-40, 1))
    seperatorLbl.backgroundColor = UIColorFromRGB(0x9B9B9B)

    groupsLbl = UILabel(frame: CGRectMake(20, seperatorLbl.frame.maxY + 15, 30, 20))
    groupsLbl.text = &#34;Groups:&#34;
    groupsLbl.makeNameLabelFormat()
    groupsLbl.sizeToFit()

    groupsCountLbl = UILabel(frame: CGRectMake(groupsLbl.frame.maxX + 5, seperatorLbl.frame.maxY + 15 , 40, 20))
    groupsCountLbl.sizeToFit()

    let myView = UIView(frame: CGRectMake(0,0,bounds.width, groupsCountLbl.frame.maxY + 10))

    myView.addSubview(imageSliderVC.view)
    myView.addSubview(layerView)
    myView.addSubview(noButton)
    myView.addSubview(yesButton)
    myView.addSubview(nameLbl)
    myView.addSubview(hashtagLbl)
    myView.addSubview(seperatorLbl)
    myView.addSubview(groupsLbl)
    myView.addSubview(groupsCountLbl)



    table.tableHeaderView = myView
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我通过在 IB 中使用 <code>TableView</code> 实现 <code>UITableViewController</code> 而不是普通的 <code>UIViewController</code> 解决了这个问题</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 带有 HeaderView 的 UITableView 不滚动,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/39066417/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/39066417/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 带有 HeaderView 的 UITableView 不滚动