Here my code :
@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
}
So in my didselectrow method
i am check whether the selected string is equal.And if its equal i will keep the ui as some color chnage. But its not working ??
i saw this tutorial : http://www.aegisiscblog.com/how-to-implement-custom-dropdown-list-in-swift.html
please help me out..
Thanks