带HeaderView的UITableView不滚动

时间:2016-08-21 16:29:58

标签: ios swift uitableview

我正在尝试创建一个屏幕,其中包含一些UIElements和一个UITableView。 为了使所有内容都可滚动,我实现了UITableViewtableHeaderView,其中包含UIElements

现在,视图无法正确滚动显示所有UITableViewCells

这是我到目前为止所遵循的步骤:

  1. 以编程方式创建UIView及其Subviews
  2. 将自定义UIView设置为table.tableHeaderView
  3. 加载data
  4. 我到底错过了什么?

    编辑:三个步骤的代码

    1,2。
            let bounds = UIScreen.mainScreen()。bounds

        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 = "Groups:"
        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
    

1 个答案:

答案 0 :(得分:0)

我通过在IB中实施UITableViewController而不是普通的UIViewControllerTableView解决了这个问题