• 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
Re: NSTableView Binding NSSortDescriptor
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView Binding NSSortDescriptor


  • Subject: Re: NSTableView Binding NSSortDescriptor
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 25 Nov 2011 13:51:18 -0800

On Nov 25, 2011, at 13:21 , Ben wrote:

> @property (readonly, strong, nonatomic) IBOutlet NSArray *sortDescriptorArray; (plus @synthesize it in the implementation)
>
>
> In my applicationDidFinishLaunching method I have...
>
>
> NSSortDescriptor * sd = [[NSSortDescriptor alloc] initWithKey:@"address" ascending:YES];
> sortDescriptorArray = [NSArray arrayWithObject:sd];

Well, one obvious difficulty is that if the NIB file containing the table is loaded before applicationDidFinishLaunching, this code won't work because it's not KVO compliant. The correct code would be:

	self.sortDescriptorArray = [NSArray arrayWithObject:sd];

if you took away the 'readonly' attribute, or:

	[self willChangeValueForKey: @"sortDescriptorArray"];
	self.sortDescriptorArray = [NSArray arrayWithObject:sd];
	[self didChangeValueForKey: @"sortDescriptorArray"];

if you didn't.

However, it would make more sense (and solve the above difficulty) to put the code in the getter instead:

	- (NSArray*) sortDescriptorArray {
		if (!sortDescriptorArray)
			sortDescriptorArray = …;
		return sortDescriptorArray;
	}

The other odd thing in your code is the 'IBOutlet' annotation on the property. You don't need or want to mark it as an outlet unless you're going to connect it to something in the NIB file. If you did connect it to something in the NIB file, then you don't want to put code to initialize it in the delegate.

There's a very loose sense in which outlets and bindings are mutually exclusive (although there are specific scenarios where you end up with both).


_______________________________________________

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: NSTableView Binding NSSortDescriptor
      • From: Ben <email@hidden>
    • Re: NSTableView Binding NSSortDescriptor
      • From: Quincey Morris <email@hidden>
References: 
 >NSTableView Binding NSSortDescriptor (From: Ben <email@hidden>)

  • Prev by Date: Re: "byte orders" question
  • Next by Date: Re: NSTableView Binding NSSortDescriptor
  • Previous by thread: NSTableView Binding NSSortDescriptor
  • Next by thread: Re: NSTableView Binding NSSortDescriptor
  • Index(es):
    • Date
    • Thread