Не могу обновить значение в классе - PullRequest
1 голос
/ 08 мая 2019

Это мой класс Designed.

open class SBCity: NSObject {
    var CM_CityID:String = ""
    var CM_CityName:String = ""
    var CM_OrderBy:Int = 0

    required public init(CM_CityID:String,CM_CityName:String,CM_OrderBy:Int) {
        self.CM_CityID = CM_CityID
        self.CM_CityName = CM_CityName
        self.CM_OrderBy = CM_OrderBy
    }
}

ViewController

В ViewController у меня есть tableView, содержащий следующие три детали в каждой ячейке.Я просто добавляю значение в класс к моему методу UITableView didSelect.

var source:SBCity?
var destination:SBCity?

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if filterdata.count != 0 {
        return filterdata.count
    } else {
        if tableView == FirstTable {
            return ArrcityList.count
        } else {
            return ArrcityList.count
        }
    }
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    if tableView == FirstTable{
        let cell = tableView.dequeueReusableCell(withIdentifier: "RecentCityCell") as! RecentCityCell
        cell.cities = ArrcityList[indexPath.row]
        return cell
    }
    //if tableView is not table1 then

    if filterdata.count != 0 {
        let cell2 = tableView.dequeueReusableCell(withIdentifier: "SourceCityCell")
            as! SourceCityCell
        cell2.cities = filterdata[indexPath.row]
        return cell2
    } else {
        let cell2 = tableView.dequeueReusableCell(withIdentifier: "SourceCityCell")
            as! SourceCityCell
        cell2.cities = ArrcityList[indexPath.row]
        return cell2
    }
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if isSelectingSource {
        if tableView == FirstTable{
            let indexPath = tableView.indexPathForSelectedRow
            let crrtCell = tableView.cellForRow(at: indexPath!) as! RecentCityCell
            self.source = SBCity(CM_CityID: crrtCell.lblID.text!, CM_CityName: crrtCell.lblCity1.text!, CM_OrderBy: 0)
            source = SBCity(CM_CityID: crrtCell.lblID.text!, CM_CityName: crrtCell.lblCity1.text!, CM_OrderBy: 0)
            SourceCityName = crrtCell.lblCity1.text!
            self.moveOnNextVc()
        } else {
            let indexPath = tableView.indexPathForSelectedRow
            let crrtCell = tableView.cellForRow(at: indexPath!) as! SourceCityCell
            self.source = SBCity(CM_CityID: crrtCell.lblID2.text!, CM_CityName: crrtCell.lblCity2.text!, CM_OrderBy: 0)
            source = SBCity(CM_CityID: crrtCell.lblID2.text!, CM_CityName: crrtCell.lblCity2.text!, CM_OrderBy: 0)
            SourceCityName = crrtCell.lblCity2.text!
            self.moveOnNextVc()
        }
    } else if isSelectingDestination {
        if tableView == FirstTable{
            let indexPath = tableView.indexPathForSelectedRow
            let crrtCell = tableView.cellForRow(at: indexPath!) as! RecentCityCell
            self.destination = SBCity(CM_CityID: crrtCell.lblID.text!, CM_CityName: crrtCell.lblCity1.text!, CM_OrderBy: 0)
            destination = SBCity(CM_CityID: crrtCell.lblID.text!, CM_CityName: crrtCell.lblCity1.text!, CM_OrderBy: 0)
            DestinationCityName = crrtCell.lblCity1.text!
            self.moveOnNextVc()
        } else {
            let indexPath = tableView.indexPathForSelectedRow
            let crrtCell = tableView.cellForRow(at: indexPath!) as! SourceCityCell
            self.destination = SBCity(CM_CityID: crrtCell.lblID2.text!, CM_CityName: crrtCell.lblCity2.text!, CM_OrderBy: 0)
            destination = SBCity(CM_CityID: crrtCell.lblID2.text!, CM_CityName: crrtCell.lblCity2.text!, CM_OrderBy: 0)
            DestinationCityName = crrtCell.lblCity2.text!
            self.moveOnNextVc()
        }
    }
}

Но оно не добавляет значение в класс.это показывает ноль каждый раз.Что не так с кодом?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...