Wednesday, April 6, 2011

Core Data and NSTableView show content as title

I'm working on a menubar note-taking app with Simplenote syncing support, and it's been using a separate title and content for each note. It shows the title in an NSTableView and the content in an NSTextView, but now I would like for it to show the content as the title in the table view like in Simplenote. My problem is that I would like for it to show the title only up until it reaches a newline, but I don't know how to do it.

From stackoverflow
  • Simplest way is to break apart the string using -componentsSeparatedByString: and pass in \n which will return an array with the components broken apart. Then grab the zeroth element from the array.

    Marcus S. Zarra : Note that you are not going to be able to do this in IB so I would suggest writing a convenience method in the `NSManagedObject` subclass to handle this and return the zeroth element. It will make your table bindings **much** easier.
    ausgat : So, I have to subclass NSManagedObject? I'm still pretty new to Core Data, bindings, etc.
    ausgat : Nevermind, I got everything working. Thanks. :)

0 comments:

Post a Comment