5 Replies
      Latest reply on Feb 15, 2020 8:40 AM by Claude31
      gefa Level 1 Level 1 (0 points)

        I found in the AppKit doc Swift 5.2

             Declaration

             var clickedRow: Int { get }

         

        Unfortunately I can't resolve it resp. I don't know how to use this info in myApp

         

        Thanks for any help

        gefa

        • Re: Get the index of a row clicked in a tableview?
          Claude31 Level 8 Level 8 (8,115 points)

          The way to use:

           

                  let row = myTableView.clickedRow

           

          Note that's only for MacOS NSTableView, not iOS UITableView.

          What is your app ? iOS ? MacOS ?

           

          In iOS, you have usually the delegate

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

           

          where you get the indexPath (hence the row) once you tapped on a cell.

           

          Could you show the code where you want to use it ?

            • Re: Get the index of a row clicked in a tableview?
              gefa Level 1 Level 1 (0 points)

              Hello Claude31,

              my app is an iOS  app. Unfortunately, I can't see in the delegates (AppDelegate.swift, SceneDelegate.Swift) the delegate func you propose.

              Any idea why?

              Thanks for your help

              gefa

                • Re: Get the index of a row clicked in a tableview?
                  Claude31 Level 8 Level 8 (8,115 points)

                  Ok, so you can't use clickedRow.

                   

                  Your tableView is in a class, right ?

                   

                  How is it declared?

                  1. Subclass of UIViewController, conforming to TableView protocols

                  class MyClass : UIViewController, UITableViewDelegate, UITableViewDataSource { }

                  or

                  2. directly as subClass of tableViewController

                  class MyClass : UITableViewController { }

                   

                  In any case, you define in the class the delegate func, such as :

                   

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

                   

                  The only difference is that, in the second case, need to declare func as override

                   

                  Don't forget to set the delegate for the tableView.

                   

                  Does it answer your point ? If so, thanks to close the thread. If not, please explain what the problem is.

                • Re: Get the index of a row clicked in a tableview?
                  gefa Level 1 Level 1 (0 points)

                  Hello Claude31,

                  I could implement your delegate proposal. Examples I got:

                  row selected is: [0, 1]

                  row selected is: [0, 4]

                  row selected is: [0, 6]

                  Presumably the first integer in these arrays refers to sections.

                  Thank you very much

                   

                  Is there an analogous delegate to monitor when a selected row is unselected?

                  Thanks for your answer

                   

                  gefa