Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
I have made a simple program, that consists of an NSTableView that has columns that include text fields, sliders, and an Image view. I built it to make some simple experiments with Cocoa bindings, as I am learning them now.

All are well, the new entries are properly handled, and I can change the imageview contents to any picture I like.

The problem comes at the point where I quit the program. That's when the saving functions are called, and I am sure that I have done something wrong, because when I reopen the program (where the data should be automatically loaded), all I get are empty entries!

Can anyone check the project? It's really simple and small. Any comment would be great.
 

Attachments

  • cocoaki 1.zip
    111.8 KB · Views: 100

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
In testClass, when initWithCoder is called, it is working with the ivar properties but properties is only created in init. This fixes it:

Code:
- (void) setProperties: (NSDictionary *)newProperties
{
	[b]if (properties == nil)
		properties= [[NSMutableDictionary alloc] init];[/b]
	[properties setDictionary:newProperties];
}

You should use *real* setters and getters, and then you would have not gotten this problem :)
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
Great!

Thanks, kainjow, that corrected my problem.

Now, for another question. In the same project, let's say I have 2 or 3 pictures inside my project. In the field where the picture is displayed, I want an arbitrary picture to be displayed, whose location will be in the "name" field.

For example, if I had an image named "test.jpg" in the project and in the program I went in one entry and in the field I typed "test.jpg", the image to the right (and in the ImageView) would change to reflect the image named "test.jpg" and not the default one.

Any idea on how to do this using bindings?
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
I think I am goinf nuts...

Thanks, kainjow.

.. but what is the mistake here? I am building a thought organizer, with 2 nstableviews. 1 that holds the days, and the other one that holds the projects of a particular day. No matter how hard I try, I cannot get the project tableview to work, even if I have connected it correctly... The days table view works fine. Can anyone take a look at it, please?
 

Attachments

  • test.zip
    51.2 KB · Views: 80

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
First of all, please post the specific problem you are having so we don't have to hunt around to find it (although it was obvious when running your project).

Second, you need to initialize your variables. Bindings is accessing the "projects" array within the day class but you never created it.

This stuff is Cocoa 101. Make sure you know the fundamentals of setting up your classes' ivars and accessor methods before trying to understand bindings. You should go back and review the basics.
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
First of all, please post the specific problem you are having so we don't have to hunt around to find it (although it was obvious when running your project).

Second, you need to initialize your variables. Bindings is accessing the "projects" array within the day class but you never created it.

This stuff is Cocoa 101. Make sure you know the fundamentals of setting up your classes' ivars and accessor methods before trying to understand bindings. You should go back and review the basics.


Please don't be mean :)

Heh, I am programming in Cocoa for approx 2 years, having made applications that are used by thousands of people. But having programmed today various projects for approx 14 hours continuously, it's natural to become careless and forgetful.

Cocoa bindings are a new topic for me, since I avoided it for so much time and when I see some errors, it's difficult to imagine that I would have made such a basic mistake.

Anyway, thanks a lot for taking the time to view my code.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.