city
Tab 아래에서 표 행을 선택하고 areaOne
에있을 때 Ok
을 강조 표시하려면 city
아래의 동일한 표 행을 areaTwo button
으로 변경하더라도 강조 표시된 상태로 유지됩니다. 어떻게 이런 일이 일어나지 않도록합니까?버튼을 눌렀을 때 행을 선택하는 방법은 무엇입니까?
var citySelectedIndexPaths = [IndexPath]()
var townSelectedIndexPaths = [IndexPath]()
@IBOutlet weak var areaOne: UIButton!
@IBOutlet weak var areaTwo: UIButton!
var popValue:Int!
@IBAction func areaSelect(_ sender: UIButton) {
let areas: [[UIButton]] = [[areaOne],[areaTwo]]
switch sender {
case areaOne:
popValue = 1
case areaTwo:
popValue = 2
default: break
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let myCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CityCell
//resetting the color
myCell.backgroundColor = UIColor(white: 1.0, alpha:1.0)
switch (segCtrl.selectedSegmentIndex)
{
case 0:
myCell.myLabel.text = cityName[indexPath.row]
//I like to know how to add condition for button selected below
// so as to display popValue =1 when areaOne is tapped
//instead of me doing it manually like below
if citySelectedIndexPaths.contains(indexPath) && (popValue == 1) {
myCell.backgroundColor = UIColor(white: 1.0, alpha:0.5)
}
break
case 1:
myCell.myLabel.text = townName[indexPath.row]
if townSelectedIndexPaths.contains(indexPath) {
myCell.backgroundColor = UIColor(white: 1.0, alpha:0.5)
}
break
default:break
}
return myCell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
let cell = tableView.cellForRow(at: indexPath)!
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
let ok = UIAlertAction(title: "Ok", style: .default, handler: { (action) -> Void in
let cell = tableView.cellForRow(at: indexPath)!
cell.backgroundColor = UIColor(white: 1.0, alpha:0.5)
switch (segCtrl.selectedSegmentIndex)
{
case 0:
if citySelectedIndexPaths.contains(indexPath) {
let indexValue = citySelectedIndexPaths.indexOf(indexPath)
citySelectedIndexPaths.removeAtIndex(indexValue)
} else {
citySelectedIndexPaths.append(indexPath)
}
break
case 1:
if townSelectedIndexPaths.contains(indexPath) {
let indexValue = townSelectedIndexPaths.indexOf(indexPath)
townSelectedIndexPaths.removeAtIndex(indexValue)
} else {
townSelectedIndexPaths.append(indexPath)
}
break
default:break
}
})
alertController.addAction(ok)
present(alertController, animated: true, completion: nil)
}
당신이 에어리어 원하고 areaTwo이 무엇인지에 대한 컨텍스트를 제공 할 수 있습니다. 어쩌면 스크린 샷을 제공 할 수 있습니까? – JoGoFo
당신의 논리에서 이제는'cell.backgroundColor = UIColor (white : 1.0, alpha : 0.5)'만 보았고, 이전에 선택된 셀에 대해'cell.backgroundColor'를 리셋하기위한 스 니펫을 보지 않았습니다. – nynohu