用 TableView 的代理方法添加的header点击第一个不触发事件,但是点击第二个header触发了第二组第一行的点击事件

头发还没秃a 2016-03-11 10:10:09
直接上添加 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分,请包涵)
...全文
209 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ravatar0423 2016-03-12
  • 打赏
  • 举报
回复
HeaderCell不要继承自UITableViewCell,所以也不要调用dequeueReusableCellWithIdentifier方法来获取HeaderCell; 解决方案: 让你的HeaderCell继承UITableViewHeaderFooterView,然后调用dequeueReusableHeaderFooterViewWithIdentifier方法获取HeaderCell
AirZilong 2016-03-12
  • 打赏
  • 举报
回复

29,031

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧