致命错误在tabelview中索引超出范围

时间:2021-09-15 16:43:47

I want to navigate from tableview to different ViewController here is the code i have written I want the values of which are stored in my model class in different view controllers where ever I need them Here is the code I have written it is giving me

我想从tableview导航到不同的ViewController这里是我编写的代码我想要的值存储在我的模型类中的不同视图控制器中我需要它们这里是我写的代码给了我

fatal error: Index out of range

致命错误:索引超出范围

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 

    switch(indexPath.row)
    {
        case 0 : let v1 = self.storyboard?.instantiateViewController(withIdentifier: "pass1") as! ViewControllerngodetails
        v1.t = arrayNGO[indexPath.row]

        navigationController?.pushViewController(v1, animated: true)
        break;

        case 1 : let v2 = self.storyboard?.instantiateViewController(withIdentifier: "pass2") as! ViewController2Reg
        v2.e = arrayNGO[indexPath.row]
        navigationController?.pushViewController(v2, animated: true)

        break;
        case 2 : let v3 = self.storyboard?.instantiateViewController(withIdentifier: "pass3") as! ViewController3FCRA
        v3.t = arrayNGO[indexPath.row]

        navigationController?.pushViewController(v3, animated: true)

        break;
        case 3 : let v4 = self.storyboard?.instantiateViewController(withIdentifier: "pass4") as! ViewControllersectorkeys
        v4.t = arrayNGO[indexPath.row]

        navigationController?.pushViewController(v4, animated: true)

        case 4 : let v5 = self.storyboard?.instantiateViewController(withIdentifier: "pass5") as! ViewController5contactdet
        v5.t = arrayNGO[indexPath.row]

        navigationController?.pushViewController(v5, animated: true)

        case 5 : let v6 = self.storyboard?.instantiateViewController(withIdentifier: "pass6") as! ViewController6bnkdetails
        v6.t = arrayNGO[indexPath.row]

        navigationController?.pushViewController(v6, animated: true)
        default: break
    }

1 个解决方案

#1


0  

Try to Print arrayNGO.count on certain line to know the exact value of your Array

尝试在某行上打印arrayNGO.count以了解数组的确切值

add this line before switch statement to know your code.

在switch语句之前添加此行以了解您的代码。

print(arrayNGO.count)

#1


0  

Try to Print arrayNGO.count on certain line to know the exact value of your Array

尝试在某行上打印arrayNGO.count以了解数组的确切值

add this line before switch statement to know your code.

在switch语句之前添加此行以了解您的代码。

print(arrayNGO.count)