iosswiftxcodeuitableviewindexpath

If statement always evaluated, something always prints in cell


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:


Solution

  • 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
    }