I can't call array in the tableView delegate method cellForRow at indexPath. it gives an error message:
Cannot assign value of type string to typeString?
import UIKit
struct cellData {
var open = Bool()
var currentRides = [String]()
var RequestedRides = [String]()
var sectionData = [String]()
}
class RideResultViewController: ContentViewController, UITableViewDelegate, UITableViewDataSource {
let currentRidesArray = ["1", "2", "3"]
let RequestedRidesArray = ["A", "B", "C"]
var tableViewData = [cellData]()
@IBAction func segmentedValueChanged(_ sender: Any) {
}
override func viewDidLoad() {
super.viewDidLoad()
//Expandable cell initailization
tableViewData = [cellData(open: false, currentRides: currentRidesArray, RequestedRides: RequestedRidesArray, sectionData: ["cell1", "cell2", "cell3"])]
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else {return UITableViewCell()}
if segmentedControl.selectedSegmentIndex == 0 {
cell.textLabel?.text = tableViewData[indexPath.section].currentRides
} else if segmentedControl.selectedSegmentIndex == 1 {
cell.textLabel?.text = RequestedRidesArray[indexPath.row]
}
return cell
} else {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else {return UITableViewCell()}
if segmentedControl.selectedSegmentIndex == 0 {
cell.textLabel?.text = tableViewData[indexPath.section].sectionData[indexPath.row]
} else if segmentedControl.selectedSegmentIndex == 1 {
cell.textLabel?.text = tableViewData[indexPath.section].sectionData[indexPath.row]
}
return cell
}
}
The code not building. I tied to put it in a square bracket but it still gave same error.
tableViewData[indexPath.section].currentRides=> tableViewData[indexPath.section].currentRides[indexPath.row]?tableViewData[indexPath.section].currentRidesis an Array of String (ie[String]), not aString