开发者

displaying balance in core data

I have 3 entities in an example app:

Account

  • name
  • balance (NSDecimalNumber overall balance of account)
  • balances (to-many relationship with Balances)
  • transactions (many-to-many relationship with Transaction.accounts)

Transaction

  • payee
  • amount
  • accounts (many-to-many relationship with Account.transactions)
  • balances (many-to-one relationship with Balances.transaction)

Balance

  • amount
  • account (one-to-many relationship with Account.balances)
  • transaction (one-to-many relationship with Transaction.balances)

I want to display the transactions of a particular account in an NSTableView. The problem comes in when I want to display the balance of the current account. Because a transaction may be associated with multiple accounts, it may have multiple balances. I can't think of a way to select the particular b开发者_C百科alance associated with the current account being displayed in an NSTableColumn. Does anyone have any suggestions of how to change the model or how to connect things up to the NSTableView in such a way that the proper balance is displayed?

The only thing I can think of is to create a sub-class of NSCell that knows how to select the balance associated with the current account view or an NSValueTransformer that does a similar thing. This seems like a very inelegant solution though. If there is a better way I would like to know how.

Update

Here's a screenshot of a demo app that illustrates the above. I would like the far right column to display the balance as of that specific transaction. Works well enough if the transaction has a balance attribute; however, in my app the balance is stored in a separate table because there may be multiple types of balances for each transaction. I can't figure out how to get it to display the proper balance in the table view though:

displaying balance in core data


Have you considered populating the table via this NSTableViewDataSource method:

- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex

I know, it looks ugly, but you can do somersaults with it.


Bind the table column's value binding to your array controller of Accounts with the controller key selection and the model key path balance.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜