Re: Binding Tableviews (newbie) problems/questions
Re: Binding Tableviews (newbie) problems/questions
- Subject: Re: Binding Tableviews (newbie) problems/questions
- From: Tim Lucas <email@hidden>
- Date: Fri, 14 Jan 2005 16:47:31 +1100
Haven't checked out the example... but...
On 14/01/2005, at 4:02 PM, Vince Ackerman wrote:
I added the mutableArrayValueForKey to your addEmail method with the
this result:
- (IBAction) addEmail: (id)sender
{
// get current mailbox
int mailboxRow = [mailboxTable selectedRow];
if (mailboxRow < 0) return;
Mailbox * mailbox = [[self mailboxes] objectAtIndex: mailboxRow];
// get mutable array of emails
// and add new instance
NSMutableArray * emails = [mailbox emails];
Email * newEmail = [[Email alloc] init];
[[self mutableArrayValueForKey: @"emails"] addObject: newEmail];
// <------ added/replaced
// reload table and select new item
[emailTable reloadData];
[emailTable selectRow: ([emails count] - 1) byExtendingSelection:
NO];
}
<snip/>
Thanks for looking at this... I guess I could just ditch the bindings
and go back with the glue code if I want to modify the arrays behind
the controllers back :-(
Looks like you have more to worry about than glue code. Bindings are
simple if you have a well thought out object model.
I don't see why your addEmail method shouldn't be as simple as:
- (IBAction) addEmail: (id)sender
{
Mailbox *m = [self currentMailbox];
Email *e = [[[Email alloc] init] autorelease];
// set email properties
[m addEmail:e];
[self selectEmail:e];
}
with your Mailbox doing a willChange/didChange for its "emails" key
inside its "addEmail" method.
You could have an ArrayController (1) of Mailboxes, and an
ArrayController (2) of Emails. (2) would be bound to (1) with the key
"selection.emails".
btw you forgot a [newEmail release]
- tim lucas
http://www.toolmantim.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden