My problem is I returned the rows to be count
, as a result when I try to run my code, the array in the UserDefaults is only evaluated to the first 4 objects. And even if the if statement = false, the. row will have a title as title
and detailText as subtitle
Problems are:
ooo (long array) starts from 0 when doing indexpath.row and goes to count
if statement always is evaluated
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "eventO", for: indexPath)
rol = (UserDefaults.standard.stringArray(forKey: "data") ?? [String]())[indexPath.row]
self.title = dat
let ooo = (UserDefaults.standard.stringArray(forKey: "data") ?? [String]())
///This function starts from 0 when doing indexpath.row and goes to count
///This is the main problem
if ooo != []{
if ooo[indexPath.row] == dat{
cell.textLabel?.text = (UserDefaults.standard.stringArray(forKey: "array") ?? [String]())[indexPath.row]
cell.detailTextLabel?.text = (UserDefaults.standard.stringArray(forKey: "dae") ?? [String]())[indexPath.row] + ": " + (UserDefaults.standard.stringArray(forKey: "array2") ?? [String]())[indexPath.row]
}
}
return cell
}
Thanks to everyone I found a problem,I accidentally inserted an extra if statement. The resulting code is:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "eventO", for: indexPath)
let gog = UserDefaults.standard.stringArray(forKey: "array") ?? [String]()
let log = UserDefaults.standard.stringArray(forKey: "array2") ?? [String]()
let rog = UserDefaults.standard.stringArray(forKey: "dae") ?? [String]()
for i in 0...ooo.count-1{
if ooo[i] == dat{
see.append(gog[i])
lee.append(log[i])
mee.append(rog[i])
}
}
rol = (UserDefaults.standard.stringArray(forKey: "data") ?? [String]())[indexPath.row]
self.title = dat
if ooo != []{
cell.textLabel?.text = see[indexPath.row]
cell.detailTextLabel?.text = mee[indexPath.row] + ": " + lee[indexPath.row]
}
return cell
}