PDA

View Full Version : I need a walk through - Arrays of arrays of objects




slooksterPSV
Jul 27, 2006, 09:45 PM
Ok, I'm extending my MDM application (MoneyData Manager). Here's what I need help with doing:

The user will have two table views, one to choose their account and the second to display transactions with that account. Ok I've got it to where you can add data to one or the other, but selecting won't show what should be in the other. Anyways I know how to do that. Here's my problem:

When I archive the data, how will I get the data for the other transactions? I figure I'll have to make an array of an array of the data.
E.g. Accounts->Transactions->the actual transactions data, so you'd have this:
Account 1:
Transactions:
a, b, c
a, b, c
Account 2:
Transactions:
a, b, c
a, b, c

Now I think I know how I'll unpack the data, unpack the data into an array then unpack each array item into an array for those transactions.

Do you follow with what I'm asking?
I want to know how I'd get the data from the other accounts. I guess I'm not sure what I'd do, should I do a for loop or... see I'm lost on what to do.



slooksterPSV
Jul 27, 2006, 10:13 PM
Ok I started to write it and it makes sense now, but now I have another issue, when the user double dlicks on the account name, it deallocates MoneyData which is a class I need to use, so I don't know how I can keep it from deallocating.

EDIT: I'm not sure how its deallocating it. Here's what I'm doing:
When the user creates an account and clicks on it, it SHOULD load the data for that account via an array stored in the account. e.g.
//... rest up here
{
NSString *accountName;
NSMutableArray *transactions;
}
//... rest down here

ok now here's what I do when the user clicks on the table:

- (void)showTransactionsForAccount:(id)sender
{
NSLog(@"You chose %d", [accountView selectedRow]);
if([accountView selectedRow] >= 0)
{
transactions = [[accounts objectAtIndex:
[accountView selectedRow]]transactions];
if(transactions == nil)
{

}else{
NSLog(@"Hello");
[self setTransactions:transactions];
[tableView setNeedsDisplay:YES];
}
}
}

I set the MyDocument.h's transactions value to the accounts transaction data. Here's the insertobject method it calls:

- (void)insertObject:(MoneyData *)d inTransactionsAtIndex:(int)index
{
int row = [tableView numberOfRows]-1;

// Add the inverse of this operationg to the undo stack
NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self] removeObjectFromTransactionsAtIndex:index];
if(![undo isUndoing]) {
[undo setActionName:@"Insert Transaction"];
}
//Add the Person to the array
if(row > -1)
{
MoneyData *prev = [transactions objectAtIndex:row];
[d setCurrentAvail:[prev totalAmount]];
[d setTypeOfTransaction:[prev typeOfTransaction]];
}
[self startObservingTransaction:d];
[transactions insertObject:d atIndex:index];
}

But it won't do anything if the user has created and clicked on an account cause it says key value coding blah blah blah while MoneyData is being deallocated.

caveman_uk
Jul 28, 2006, 02:49 AM
Have you had a look at Cocoa bindings? They aren't necessarily what you need yfor every job but they're really good for situations like this where you have a selection for one GUI object that then shows the details of that selection somewhere else.

whooleytoo
Jul 28, 2006, 09:05 AM
What's the exact error message you're getting?

slooksterPSV
Jul 28, 2006, 10:06 AM
- (void)showTransactionsForAccount:(id)sender
{
NSLog(@"You chose %d", [accountView selectedRow]);
if([accountView selectedRow] >= 0)
{
NSMutableArray *transAcct = [[NSMutableArray alloc] initWithArray:[[accounts objectAtIndex:
[accountView selectedRow]]transactions]];
NSLog(@"%@", transAcct);
if(transAcct != nil) {
[transactions release];
transactions = transAcct;
[self setTransactions:transactions];
[tableView setNeedsDisplay:YES];
[transAcct release];
}
}
}


I have an array in my Account.h which will hold the transactions, so that I can click on an account and it'll go through the array of accounts to get the accounts transactions.
You can see some issues with the above code? I'm not sure how to do all this.

Account has its own NSArrayController with a binding to its modeler accountName.

Do you just want me to zip the entire project and see if you guys can figure it out, I'm so lost.

EDIT: When I choose a different name or click on the same account it goes into the GDB and starts giving me error locations, but I'm not sure what the error is.

whooleytoo
Jul 28, 2006, 10:09 AM
Yup, feel free to post it up here if you like.

slooksterPSV
Jul 28, 2006, 10:20 AM
http://rapidshare.de/files/27338850/MDM.zip.html

whooleytoo
Jul 28, 2006, 10:25 AM
http://rapidshare.de/files/27338850/MDM.zip.html

Ok, I'm on Panther here so I can't load the project until I get to my MacBook at home later.

In the meantime, is there any output to the console when the error occurs? Have you tried stepping through the code, and if so at what point do the errors occur?

almightyshoe
Jul 28, 2006, 06:43 PM
Why can't you load the files on Panther? (I ask because I work tech support at the Uni, and we have one powerbook here running Panther, while the rest of the campus runs Tiger-soon-to-run-Leopard)