• 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
programatically updating UI for NSArrayContoller/NSTableView combo
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

programatically updating UI for NSArrayContoller/NSTableView combo


  • Subject: programatically updating UI for NSArrayContoller/NSTableView combo
  • From: Russell Gray <email@hidden>
  • Date: Sat, 9 Jan 2010 08:10:04 +1100

I am having trouble trying to get a tableView to update its contents, when bound to an NSArrayController - but only when new objects are added. removal, and updating of current objects works fine.

The arraycontroller is bound to a mutablearray of dictionaries, and will update correctly only after removal/updating of other objects via  the UI. (ie... an NSButton/IBAction)

the add method is not accessed through an NSButton in the UI, because it can receive data from other sources.
I have tried using willUpdateValueforKey/didUpdateValueforKey and various other methods, nothing will force update the UI.

I am using custom table cells, as seen in this tutorial:
http://www.martinkahr.com/2007/05/04/nscell-image-and-text-sample/index.html

and initialising the arrayController like so in my init method:

subscriptions = [[NSMutableArray alloc] init];
		NSString *applicationSupportFolder = [SABApplicationSupportFolderPath stringByExpandingTildeInPath];
		NSString *subscriptionsPlistPath = [applicationSupportFolder stringByAppendingPathComponent:SABSubscriptionsPlistFullName];
		NSArray* subscriptionsArray = [NSArray arrayWithContentsOfFile:subscriptionsPlistPath];

		int i = 0;
		for (NSDictionary *child in subscriptionsArray)
		{
			NSDictionary* subscriptionsDictionary = [subscriptionsArray objectAtIndex:i];
			SubscriptionInfo* subscriptionInfo   = [[[SubscriptionInfo alloc] initWithInfoDictionary: subscriptionsDictionary] autorelease];
			[subscriptions addObject: subscriptionInfo];
			i++;
		}

I also have a method to flush out the arrayController and reload from a plist here:

- (void)refreshArrayContollerContent
{
	subscriptions = [[NSMutableArray alloc] init];
	NSString *applicationSupportFolder = [SABApplicationSupportFolderPath stringByExpandingTildeInPath];
	NSString *subscriptionsPlistPath = [applicationSupportFolder stringByAppendingPathComponent:SABSubscriptionsPlistFullName];
	NSArray* subscriptionsArray = [NSArray arrayWithContentsOfFile:subscriptionsPlistPath];

	int i = 0;
	//clear subscriptionsArrayController and reload
	NSArrayController* resetArrayController = subscriptionsArrayController;
	[[resetArrayController content] removeAllObjects];

	for (NSDictionary *child in subscriptionsArray)
	{
		NSDictionary* subscriptionsDictionary = [subscriptionsArray objectAtIndex:i];
		SubscriptionInfo* subscriptionInfo   = [[[SubscriptionInfo alloc] initWithInfoDictionary: subscriptionsDictionary] autorelease];
		[subscriptionsArrayController addObject: subscriptionInfo];
		i++;
	}
}

and here is the relevant part of my add method:

	// Create our Subscriptions plist file.
	NSDictionary *output;
	output = [NSDictionary dictionaryWithObjectsAndKeys:title, @"feedNameKey",
														urlString, @"feedURLKey",
														defaultValue, @"feedUpdatedKey", nil];

	[subscriptionsArray addObject: output];

	// Write the Subscriptions plist file.
	[subscriptionsArray writeToFile:subscriptionsPlistPath atomically:YES];
	[self refreshArrayContollerContent];

does anyone have any ideas?

thanks in advance.


Russell_______________________________________________

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: programatically updating UI for NSArrayContoller/NSTableView combo
      • From: mmalc Crawford <email@hidden>
  • Prev by Date: Re: Flicker Free Drawing
  • Next by Date: Re: Flicker Free Drawing
  • Previous by thread: Re: Flicker Free Drawing
  • Next by thread: Re: programatically updating UI for NSArrayContoller/NSTableView combo
  • Index(es):
    • Date
    • Thread