Re: How to NSTableView and NSArrayConroller
Re: How to NSTableView and NSArrayConroller
- Subject: Re: How to NSTableView and NSArrayConroller
- From: Scott Stevenson <email@hidden>
- Date: Thu, 28 Dec 2006 05:33:10 -0800
On Dec 27, 2006, at 9:47 PM, Craig Laird wrote:
I am hoping that someone can help me with this, as a newbie to
Cocoa please be nice :)
[...]
@implementation MyController
- (void)awakeFromNib
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ABAddressBook *book = [ABAddressBook sharedAddressBook];
contact = [book people];
NSLog( [contact description] );
[pool release];
return 0;
}
@end
You don't need a lot of this. Use this instead:
@implementation MyController
- (void)awakeFromNib
{
ABAddressBook *book = [ABAddressBook sharedAddressBook];
contact = [[NSMutableArray alloc] initWithArray:[book people]];
NSLog( [contact description] );
}
@end
See below for an explanation.
So what else do I need to do ??
My objective is to list all the contacts in the Address Book and
then sort the alphabetically
The issue is essentially that you need to make sure the array stays
around by doing something like this:
contact = [[NSMutableArray alloc] initWithArray:[book people]];
If you don't do this, the array will likely go away and the app will
crash (or at least not work correctly). You also have to make sure
you do [contact release] in MyController's -dealloc method. Make one
if it doesn't exist:
- (void) dealloc
{
[contact release];
[super dealloc];
}
Do your best to read up on Objective-C memory management so
understand what's going on.
The other thing is that I don't think ABPerson implements a method
called -name (though I could be wrong), so this might not work at
all. If it doesn't, you'll probably have to create your own class
which *does* have a -name method and gets its name data from an
ABPerson instance.
To do that, you'd use ABRecord's -valueForProperty: method with
kABFirstNameProperty and kABLastNameProperty.
That might be sort of confusing if you're a newbie but this isn't
completely simple stuff. Trying to explain it all in a single email
would take quite a bit of time. Hopefully you have enough to get
started.
Hope that helps,
- Scott
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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