0
我将xcode从7.3.1升级到8并转换为swift 2.2,除了故事板是一团糟之外,一切工作除了以编程方式添加UIView。addSubview转换后不工作
之前工作正常,现在没有任何显示,也没有错误。有任何想法吗?
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
//create view
let vw = UIView()
vw.backgroundColor = UIColor(red: 0.9137, green: 0.9176, blue: 0.9216, alpha: 1.0) /* #e9eaeb */
//create label inside view
let label: UILabel = UILabel()
label.frame = CGRectMake(0, 0, 200, 28)
label.textAlignment = NSTextAlignment.Left
label.textColor = UIColor.grayColor()
label.font = label.font.fontWithSize(13)
if !clearSearch {
label.text = " Recent Searches"
} else {
label.text = " Search Results"
}
vw.addSubview(label)
//create button inside view
let button: UIButton = UIButton()
button.frame = CGRectMake(self.view.frame.size.width - 45, 0, 40, 28)
button.titleLabel?.font = UIFont.systemFontOfSize(13)
button.setTitle("Clear", forState: UIControlState.Normal)
button.addTarget(self, action: #selector(deleteSearches), forControlEvents: UIControlEvents.TouchUpInside)
button.setTitleColor(UIColor(red: 0.3216, green: 0.7176, blue: 0.5333, alpha: 1.0), forState: UIControlState.Normal)
vw.addSubview(button)
return vw
}
感谢您的任何帮助。
这一切都很好。你应该验证vw在返回语句中是否为零(它应该是),然后检查看看调用代码中发生了什么。我怀疑这个问题在那里。您还应该尝试使用Debug-> View Debugging-> Capture View Hierarchy工具来查看正在发生的事情。 –
嘿,谢谢你的快速回复。是的,它看起来并不是那个功能块已经被调用了,很奇怪,我没有改变任何东西。我也尝试了像你所建议的那样的调试,它也没有出现在那里。 – user3712837
找出来了,现在需要heightForHeaderInSection。 – user3712837