0

在我返回牢房之前,我有一个tableView地方。viewForHeaderInSection我有这个代码:

headerCell.layer.zPosition = headerCell.layer.zPosition-1 

现在,这在单元格滚动到我想要的部分标题上的意义上是有效的。但是该单元格在框架的底部有 3 个按钮,当这些按钮滚动到(或者我应该说在下面)部分标题内容视图时,视图会阻止按钮并且我不能再点击按钮,即使我仍然可以看到它们,这是因为单元格内容视图是在标题视图上呈现的。

如果我进入视图层次结构,标题内容视图位于单元格视图之上,这是阻止按钮操作的罪魁祸首。

有人有工作吗?或者知道如何将 headerCell 的 Zposition 更改为按钮后面?我已经尝试了很多东西,但我需要帮助。

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    if (cellIdentifier == "vivrCell") {
        println(screenSize.width)
        if (screenSize.width < 370) {
            return 180
        }else{
            return 220
        }
    }else {
        return 0.0
    }
}

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    if (cellIdentifier == "vivrCell") {
        let headerCell = mainTable.dequeueReusableCellWithIdentifier("vivrHeaderCell") as vivrHeaderCell
        headerCell.productID = self.feedReviewResults![section]["product"]["id"].stringValue
        headerCell.cellDelegate = self
        headerCell.clipsToBounds = false
        headerCell.layer.zPosition = headerCell.layer.zPosition-1
        return headerCell
    }
    return nil
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    switch cellIdentifier {
        case "vivrCell":
            return self.feedReviewResults?.count ?? 0
        case "newCell":
            return 1
    default:
        return 1

    }
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 1
}


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    switch cellIdentifier{
        case "buzzCell":
            var buzzcell = mainTable.dequeueReusableCellWithIdentifier(cellIdentifier) as buzzCell
            return buzzcell
        case "vivrCell":
            var vivrcell = mainTable.dequeueReusableCellWithIdentifier(cellIdentifier) as vivrCell
            vivrcell.review = self.feedReviewResults![indexPath.section]
            vivrcell.reviewID = self.feedReviewResults![indexPath.section]["id"].stringValue
            if let state = self.feedReviewResults![indexPath.section]["current_helpful"].boolValue as Bool?{
                vivrcell.helpfullState = state
            }
            vivrcell.wishlistState = true 
            vivrcell.cellDelegate = self
            vivrcell.layer.zPosition = vivrcell.layer.zPosition
            vivrcell.backgroundView = nil
            vivrcell.contentView.backgroundColor = UIColor.clearColor()
            return vivrcell
        default:
            let noNewProductsView = UIView(frame: CGRectMake(0, 0, self.view.frame.width, self.view.frame.height))
            noNewProductsView.backgroundColor = UIColor.whiteColor()
            let checkBackLabel = UILabel(frame: CGRectMake(0, 0, 200, 60.0))
            checkBackLabel.numberOfLines = 3
            checkBackLabel.textAlignment = NSTextAlignment.Center
            checkBackLabel.center = CGPointMake(self.view.center.x, self.view.center.y-100)
            checkBackLabel.text = "Check back for new products!"
            noNewProductsView.addSubview(checkBackLabel)
            var newcell = mainTable.dequeueReusableCellWithIdentifier(cellIdentifier) as newCell
            newcell.contentView.addSubview(noNewProductsView)
            return newcell

    }
}
4

3 回答 3

0

也许您只需要忽略标题上的点击即可。在标题上设置 userInteractionEnabled = NO。

于 2015-05-13T16:09:53.213 回答
0

如果 userInteractionEnabled 为 NO 不起作用,因为您在部分标题上也有按钮,请将其添加到标题的子类中:

// We don't want touches, but we do want our subviews to get them.
// (So userInteractionEnabled = NO won't work, that'll stop subviews getting touches)
-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    id hitView = [super hitTest:point withEvent:event];
    return (hitView == self) ? nil : hitView;
}
于 2015-05-14T20:28:54.020 回答
0
sectionView.userInteractionEnabled = false
于 2016-04-24T12:35:01.330 回答