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: