problem with UITableView and moving from one view controller to another

0

Hello friends, the problem is this I am trying a taleView containing divisors and in those divisions different things and when one of them is touched, I would send it to another view, that is to say one second the problem is that when they are touched they always send to the same view is to say the same segue, try different ways but I always give the same thing in a single view the cells

    import UIKit
    class ViewControllerGeometry: UIViewController , UITableViewDelegate , UITableViewDataSource {
        var tableArray : [Problems] = []
        var tableArrayGeometryProblem : [Problemp] = []

         var segueIdentifiers = ["prueba" , "B", "C"]



        override func viewDidLoad() {
            super.viewDidLoad()
            let geometryproblem = Problems (name : "a")
            tableArray.append(geometryproblem)


            let perimeterProblem = Problemp(nameGeometryProblem: "c")
            tableArrayGeometryProblem.append(perimeterProblem)

            // Do any additional setup after loading the view.
        }
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }


        func numberOfSections(in tableView: UITableView) -> Int {
            return 4
        }

        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {



            switch section{
            case 0:
                return tableArray.count

            case 1 :

                return tableArrayGeometryProblem.count



            default:
                return 0
            }


        }




        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCell(withIdentifier: "cellGeometryproblem")! as  UITableViewCell


            let geometryproblem = tableArray [indexPath.row]

            let perimeterProblemCalculation = tableArrayGeometryProblem [indexPath.row]
            switch indexPath.section {

            case 0:

                cell.textLabel?.text = geometryproblem.name
            case 1 :
                cell.textLabel?.text = perimeterProblemCalculation.nameGeometryProblem


            default:
                return cell
            }




            return cell
        }
        func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            performSegue(withIdentifier: segueIdentifiers[indexPath.row], sender: self)
        }

        func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
            var title = ""


            switch section {
            case 0:
                title = "Area calculation "
            case 1 :

                title = "Pe

rimeter calculation "

        case 2 :

            title = "Sen theorem "

        case 3 :

            title = "Inside angles of the triangle "



        default:
            break
        }
        return title
    }

}
    
asked by Liantony Pozo 22.07.2017 в 01:40
source

1 answer

1

As far as I understand, press where you press always go to the same controller, which is pointing the segue of "test". If so, I think you have a bit of a mess with sections and rows.

You have 2 arrays, tableArray and tableArrayGeometryProblem defined and each array only has 1 element. In the table you define 4 sections (func numberOfSections) and to know how many cells there are in each section you return the number of elements of the arrays, but only for the first 2 sections. The problem of always going to the same controller where you press pulses is given in the func tableView (_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

You are telling it to go to the segue that is in the indexPath.row position of your segues array, since in any section you only have one row, so press where you press, indexPath.row = 0 always. The value of segueIdentifiers [0]="test"

If what you want to do is that according to you click on in the first cell of the first section or in the first cell of the second section you go to "test," B "or" C "you have to check the section, not the row, so you should put:

performSegue(withIdentifier: segueIdentifiers[indexPath.section], sender: self)

And you have to ensure that when you have 4 sections with values, when you click on the last one it will crack because there are no segueIdentifiers [3]. In this case, you will not go for the "C" segue

    
answered by 24.07.2017 / 13:52
source