直接上添加 header 的代码吧:
    func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{
        let cellID = "headerCell"
        var headerCell = tableView.dequeueReusableCellWithIdentifier(cellID)
            as? HeaderCell
        headerCell?.backgroundColor = UIColor.greenColor()
        if(headerCell == nil){
            headerCell = HeaderCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: cellID)
        }
        
        switch section {
        case 0:
            headerCell!.headerLabel.text = "模式"
            break
        case 1:
            headerCell!.headerLabel.text = "风速"
            break
        default:
            headerCell!.headerLabel.text = "other"
            break
        }
        
        return headerCell!
    }

如图,绿色部分为header,点击第一个不会触发cell的事件,但是点击第二个和之后的header会触发当前组第一个cell的点击事件,望高手们看看到底哪里出了问题,谢谢(实在是没分数了,仅有20分,请包涵)
解决方案
20
HeaderCell不要继承自UITableViewCell,所以也不要调用dequeueReusableCellWithIdentifier方法来获取HeaderCell;
解决方案:
让你的HeaderCell继承UITableViewHeaderFooterView,然后调用dequeueReusableHeaderFooterViewWithIdentifier方法获取HeaderCell
解决方案:
让你的HeaderCell继承UITableViewHeaderFooterView,然后调用dequeueReusableHeaderFooterViewWithIdentifier方法获取HeaderCell