4 Replies
      Latest reply on Jan 18, 2020 2:34 AM by MPHaskins
      MPHaskins Level 1 Level 1 (0 points)

        Hi,

         

        does anyone know of any example showing how you can edit a row in a NSBrowser?

         

        What I'm trying to achieve is something along the lines of Finder. Click once to select a row, click again to edit the name.

         

        Thanks,

         

        Mark

        • Re: NSBrowser - edit cell contents
          Claude31 Level 8 Level 8 (7,895 points)

          Could you show the code you have so far ?

           

          Did you study the doc:

          https://developer.apple.com/documentation/appkit/nsbrowser

          In particular

          func indexPath(forColumn: Int) -> IndexPath

          Returns the index path of the item whose children are displayed in the given column.

           

          func editItem(at indexPath: IndexPath, with event: NSEvent?, select: Bool)

           

           

          This tutorial is a bit old (may require some update), but the logic's there.

          h ttp://dcandi.com/post/cocoa-filesystem-browser/

            • Re: NSBrowser - edit cell contents
              MPHaskins Level 1 Level 1 (0 points)

              Hi,

               

              I can't really provide any code, but what I have is a NSBrowser hooked into CoreData, with the ability to add and remove entities in the hiearchy.

               

              I've tried hooking a double click event up to an IBAction (though a single click is what I'm ultimately after), from here I can get a reference to the browser. Then I was attempting to get the selected item in the appropriate column, but on the first column I was getting an empty array back when printing the indexPath. I must be doing something wrong there. I removed the non working code so I can't post here.

               

              I have read the docs, but I'm obviously missing something.

               

              I have seen that dcandi code before but it doesn't handle editing of file names, by clicking.

               

              I'll have another go at the indexpath func, and see if I implemented my logic wrong. If I still don't have any look I'll look to post some of the code here.

               

              thanks

               

              Mark

                • Re: NSBrowser - edit cell contents
                  Claude31 Level 8 Level 8 (7,895 points)

                  Well, it would really be easier to read the code than reading  paraphrase of it.

                   

                  I can't really provide any code,

                   

                  but what I have is a NSBrowser hooked into CoreData, with the ability to add and remove entities in the hiearchy.

                  Did you kook in code ? If so, please show

                   

                  I've tried hooking a double click event up to an IBAction (though a single click is what I'm ultimately after), from here I can get a reference to the browser.

                  You mean the NSBrowser ?

                  But to get a refernce, it would be easier to declare an IBOutlet. Why not ?

                   

                  Then I was attempting to get the selected item in the appropriate column,

                  Please show code

                   

                  but on the first column I was getting an empty array back when printing the indexPath. I must be doing something wrong there.

                  Please show code, with the print statement

                   

                  I removed the non working code so I can't post here.

                  Why did you need to remove to post here ?

                   

                  Conclusion: if you still want some help, please help others to help by showing the code.

                   

                  Unless you have already solved the problem.

                    • Re: NSBrowser - edit cell contents
                      MPHaskins Level 1 Level 1 (0 points)

                      Hi,

                       

                      sorry I wasn't trying to be awkard, the code was in a private repo so I couldn't link to it. I've had to move things around so I could extract the bits that you would need to look at, and made it accessible here :  https://github.com/githublemming/tempRepo.

                       

                      What I meant by I removed the non working code so I can't post here. was that I had tried something, found it didn't work, deleted it; tried something else, didn't work, etc.

                       

                      What I can't work out is:

                      * When I double click on a row, how can I make the cell editable, like you would do for a filename in Finder

                      * Then I guess when I get that working, how do I detect that editing has finished

                      * Then finally how can I get a reference to the new value.

                       

                      Thanks for trying to help.

                       

                      Mark