这是我的代码:
href=”favicon.ico?v=1”
所以在我的 @IBOutlet weak var billSelectorBtn: UIButton!
@IBOutlet weak var optionListTB: UITableView!
func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return optionsListNames.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath as IndexPath) as UITableViewCell
cell.textLabel?.text = optionsListNames[indexPath.row] as? String
return cell
}
private func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
let selectedItem = optionsListNames.object(at: indexPath.row) as! NSString
billSelectorBtn.setTitle(selectedItem as String, for: UIControlState.normal)
if selectedItem .isEqual(to: "Current Bill")
{
self.view.backgroundColor = UIColor.red
}
else if selectedItem .isEqual(to: "Water Bill")
{
self.view.backgroundColor = UIColor.green
}
optionListTB.isHidden = true
}
我检查所选字符串是否相等。如果它相等,我会将ui保持为某种颜色。但它不起作用??
我看到了这个教程:http://www.aegisiscblog.com/how-to-implement-custom-dropdown-list-in-swift.html
请帮帮我..
由于
答案 0 :(得分:1)
tableview
默认颜色为白色。要将tableview
颜色与其背景视图相匹配,您必须清除tableview
颜色,反之亦然Uitableviewcell
。
在viewdidload
添加此行
tableview.backgroundColor = UIColor.clear //tableview is your tableview outlet
并在cellForRowAt indexPath
添加,
cell.backgroundColor = UIColor.clear
在swift 3中didselect
语法已更改为
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
}
答案 1 :(得分:0)
使用“ == ”来比较字符串,而不是isEqual
。如果你的tableView占据全屏,那么让你的tableView
的backgroundColor和cell的backgroundColor清除以查看颜色变化。
答案 2 :(得分:0)
从您的委托方法中删除private
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
/// add implementation
}