Hi everyone,
I'm slowly learning Cocoa, and I've run into a problem with a program I am writing (link to code will follow).
Basically it involves 2 windows. One window creates a piece of data. Upon pressing a button to view the selected data, my main window controller calls a method upon another window controller which passes an object returned from an nsmutablearray.
However after the new window gets displayed, the object that was passed to it gets set to null.
Now i will illustrate this with parts of my actual code.
In my app controller, i have a method which gets invoked by a button:
Afterwards, my tableview gets updated properly, and I am happy.
Now once i select the item data, and click on another button called "view data" the following code gets called:
dataSetController is an instance that controls another window.
the code for setCollection: follows
I don;t use garbage collection, as I like to manage my memory myself.
So i retain collection, and then release the old value in my dataSetController, then assign the current collection to the recently retained value.
However after this method finishes executing, currentCollection is set to NULL.
I've tried running through this code in the debugger. I set a watch point on the currentCollection variable, however all I can see is it gets set to NULL in some cocoa method that I haven't implemented.
My question to you is, why does this happen, and can you help find a proper solution to this problem.
Also, I don't want to create a copy of the 'collection' as I want all the data to remain in that array.
Here's a link to the entire project: http://www.faultycode.com/vn/VNDataManager.zip
Thanks for taking a look
I'm slowly learning Cocoa, and I've run into a problem with a program I am writing (link to code will follow).
Basically it involves 2 windows. One window creates a piece of data. Upon pressing a button to view the selected data, my main window controller calls a method upon another window controller which passes an object returned from an nsmutablearray.
However after the new window gets displayed, the object that was passed to it gets set to null.
Now i will illustrate this with parts of my actual code.
In my app controller, i have a method which gets invoked by a button:
Code:
- (IBAction)createSample:(id)sender
{
VNSDataCollection *newSample = [[VNSDataCollection alloc] initWithDate:[NSDate date] Description:[[NSString alloc] initWithString:@"Empty data set"] Location:[[NSString alloc] initWithString:@"Some location"] AsynchronousType:QMR Colllection:nil];
NSLog(@"Object address after creation: %p", newSample);
[samples addObject:newSample];
[newSample release];
[tableView reloadData];
}
Afterwards, my tableview gets updated properly, and I am happy.
Now once i select the item data, and click on another button called "view data" the following code gets called:
Code:
- (IBAction)viewSample:(id)sender
{
NSInteger selectedRow = [tableView selectedRow];
if(selectedRow > -1)
{
[dataSetController setCollection:[samples objectAtIndex:selectedRow]];
[dataSetWindow makeKeyAndOrderFront:self];
}
else
NSBeep();
}
dataSetController is an instance that controls another window.
the code for setCollection: follows
Code:
- (void)setCollection:(VNSDataCollection *)collection
{
[collection retain];
[currentCollection release];
currentCollection = collection;
}
I don;t use garbage collection, as I like to manage my memory myself.
So i retain collection, and then release the old value in my dataSetController, then assign the current collection to the recently retained value.
However after this method finishes executing, currentCollection is set to NULL.
I've tried running through this code in the debugger. I set a watch point on the currentCollection variable, however all I can see is it gets set to NULL in some cocoa method that I haven't implemented.
My question to you is, why does this happen, and can you help find a proper solution to this problem.
Also, I don't want to create a copy of the 'collection' as I want all the data to remain in that array.
Here's a link to the entire project: http://www.faultycode.com/vn/VNDataManager.zip
Thanks for taking a look
Last edited: