开发者

Core data and custom NSCell

开发者 https://www.devze.com 2022-12-14 12:32 出处:网络
I am building a toy app using core data for two entities Log (attributes text and date) and Tag with a many-to-many tags relationshipfrom Log to Tag.

I am building a toy app using core data for two entities Log (attributes text and date) and Tag with a many-to-many tags relationship from Log to Tag.

I want to show logs in a table, so I:

  • created an NSArrayControlle开发者_开发知识库r instance, LogController in IB with entity set to Log (pic)
  • created a one-column NSTableView whose column is bound to LogController. pic
  • linked the LogController in my app delegate (AppDelegate) using IBOutlet. AppDelegate also has the managedObjectContext.
  • created a custom NSCell class with NSString properties mainText and tagsText that I draw onto the cell
  • I set the above two cell properties in AppDelegate in the - (void)tableView: willDisplayCell: forTableColumn: row: method. (MainController is also the table's delegate). For the tagsText I get the tags for the current log and concatenate them into a single NSString

Everything works fine, except: When I mouse-select a row that displays multiple tags the app crashes with an EXC_BAD_ACCESS. That's the only time I have any error, but I don't know what is causing it.


EXC_BAD_ACCESS is a memory error. You are using an object after deallocating it. It would be difficult to debug this without the code.

Are you using the garbage collector? You do not have to manage memory yourself on the Mac.

Are the properties in your custom NSCell declared as "retain"?

0

精彩评论

暂无评论...
验证码 换一张
取 消