• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSArrays and tableView delegates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSArrays and tableView delegates


  • Subject: NSArrays and tableView delegates
  • From: Steven Hamilton <email@hidden>
  • Date: Thu, 4 Dec 2008 14:05:07 +1000

Hi folks,
I'm looking for advice on usage of arrays in tableviews.

I have a subclassed NSWindowController. In this class I have a method that extracts data from my core data model and formulates an array of dictionaries. Also in this class I have the tableview datasource methods. The datasource methods use the standard KVC column identifier thingies to populate the table. I'm having memory leaks and I'm sure its because of the way I'm making the array available to teh data source methods.

My interface file looks like this;

@interface MLimportController : NSWindowController {
	IBOutlet NSTableView	*transactionTable;
	IBOutlet NSArrayController *accountsController;

	NSMutableArray	*importedTransactions;
	NSManagedObject *selectedAccount;
	NSNumber *selectedTransferIndex;
}

- (IBAction) recordTransactions:(id)sender;
- (IBAction) deleteSelectedTransactions:(id)sender;
- (void) setAccountSortDescriptors: (NSArray *) descriptors;
- (NSArray *) accountSortDescriptors;
- (void) importFile:(NSString *)aFile;

//delegates
- (int)numberOfRowsInTableView:(NSTableView *)tableView;
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn: (NSTableColumn *)tableColumn row:(int)row;
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)newValue forTableColumn:(NSTableColumn *)tableColumn row:(int)row;
@end


In the importFile: method is where I build they array importedTransactions. However, as it will autorelease I [retain] it so its still hanging around for the tableView methods to access it. Is this the correct way of doing this? Or should I be declaring the NSArray as a @property and using getters/setters to use it?

My memory leak is resulting in importedTransactions always having a retainCount of 1, meaning the importController class can never be deallocated by my NSDocument, meaning the documentController can never close the document properly. I'm sure I'm doing this an ugly way.

(Leopard 10.5.5 with GC on)
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSArrays and tableView delegates
      • From: Ashley Clark <email@hidden>
  • Prev by Date: Re: How to extract individual icons from icns file?
  • Next by Date: Re: custom view binding to NSTreeController
  • Previous by thread: Animation proxies and Python
  • Next by thread: Re: NSArrays and tableView delegates
  • Index(es):
    • Date
    • Thread