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

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
Hey guys, it's me again. :D

I'm branching out away from Aaron Hillegass' book to write a piece of my own software and put to use some of the stuff I've learned.

What I've got is pretty simple so far. It's basically just an app to keep track of all of your college classes. There's an NSTableView, with an NSButton titled "Add Class...". The button brings down a sheet, which has an NSTextField where the person types in the name of the class, and another NSButton ("Add") to close the sheet and add the class to the list of classes.

How I have it now, is the Add button on the sheet simply adds an instance of my CollegeClass to the table, but I can only get it to display with a static name, which then must be edited by the user later. It's difficult to explain, but this is happening because I have a Controller class which handles the NSTextField outlet, but a CollegeClass class which creates the objects. How can I tell the CollegeClass class to do... [self setClassName:[NSTextField stringValue]] if the NSTextField is an outlet designated in the Controller class? I tried importing the Controller header into the CollegeClass file, but it still doesn't recognize it.

Also, the Add button on the panel is linked to an NSArrayController that inserts the object. How can I have it do this and ALSO close the sheet?

Here's a pic!
 

Attachments

  • Picture 1.jpg
    Picture 1.jpg
    18.8 KB · Views: 120

HiRez

macrumors 603
Jan 6, 2004
6,265
2,629
Western US
Littleodie914 said:
How I have it now, is the Add button on the sheet simply adds an instance of my CollegeClass to the table, but I can only get it to display with a static name, which then must be edited by the user later. It's difficult to explain, but this is happening because I have a Controller class which handles the NSTextField outlet, but a CollegeClass class which creates the objects. How can I tell the CollegeClass class to do... [self setClassName:[NSTextField stringValue]] if the NSTextField is an outlet designated in the Controller class? I tried importing the Controller header into the CollegeClass file, but it still doesn't recognize it.
You'd probably have your CollegeClass instances keep a reference to your controller (you probably don't want to retain it), then call

[self setClassName:[[myController newClassNameField] stringValue]];

But, your application sounds like an excellent candidate to use CoreData (since you're basically talking about a database-oriented app), you might consider that.

Also, the Add button on the panel is linked to an NSArrayController that inserts the object. How can I have it do this and ALSO close the sheet?
You might have the sheet close into a method in your controller class, then from there add your new object to your array controller using code and do any other setup/cleanup necessary.
 

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
Alrighty guys, thanks a bunch for your help! I took your advice and read up on Core Data, and it's definitely what I was looking for. It's very easy to learn, but I'm having a problem with some bindings in a new (and much more complex) app I'm now working on. I'll keep it short, so...

I have this Core Data app that has two entities, Class and Assignment. The TableView on the left is bound to the title property of Class, and works just fine. What doesn't work is the top/right TableView, which I want to update when you change the selected class. How exactly should I do this? I've tried a bunch of combinations and nothing seems to work. Either I can't edit the name, or all the classes have identical assignments, etc. I guess when the selection of Class changes, the Assignment entities for the selected Class entity should show up.

Again, thanks so much for all the help. It seems I've got a new question every other day, and you guys always seem to know the answer. I'd spread my questions out to other forums, but you all are too good to go elsewhere. :D
 

Attachments

  • Picture 1.png
    Picture 1.png
    105.6 KB · Views: 104

slooksterPSV

macrumors 68040
Apr 17, 2004
3,544
306
Nowheresville
I had that problem with Core Data - still not sure how to use Core Data, but I'll learn.

Now as for when you choose a new class, how do you load data into it about assignments for that class? Well here's what you do:

1. When the user clicks the class make sure that its not already chosen.
2. When the user clicks the class and the class isn't chosen, load the data.
Well how do you get/store the data? I did it as an Array in an Array. So:
Classes Array holds Assignments array which holds data
Classes->Array->Data [ name, due date, title, etc. etc. etc.]
still sound confusing? Look at chapter 7 8 9 and 10 I think.
3. Once it loads that data, update the table.

Hmm... if you want the source to my MoneyData Manager App, PM me.
 

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
slooksterPSV said:
I had that problem with Core Data - still not sure how to use Core Data, but I'll learn.

Now as for when you choose a new class, how do you load data into it about assignments for that class? Well here's what you do:

1. When the user clicks the class make sure that its not already chosen.
2. When the user clicks the class and the class isn't chosen, load the data.
Well how do you get/store the data? I did it as an Array in an Array. So:
Classes Array holds Assignments array which holds data
Classes->Array->Data [ name, due date, title, etc. etc. etc.]
still sound confusing? Look at chapter 7 8 9 and 10 I think.
3. Once it loads that data, update the table.

Hmm... if you want the source to my MoneyData Manager App, PM me.
Alright, I see what you're saying with the arrays, it's kind of like the RaiseMan example in the book. Your method doesn't use Core Data though, is this correct? It appears to be a couple arrays that simple grab content from one another. While I'm sure this method works fine, I was hoping to build a database app like the one in the screenie completely atop a Core Data foundation.

I'll scour the web a bit to see if there're any solutions, but thanks a lot for your help, I'll keep it in mind incase I don't find anything. :)
 

slooksterPSV

macrumors 68040
Apr 17, 2004
3,544
306
Nowheresville
Littleodie914 said:
Alright, I see what you're saying with the arrays, it's kind of like the RaiseMan example in the book. Your method doesn't use Core Data though, is this correct? It appears to be a couple arrays that simple grab content from one another. While I'm sure this method works fine, I was hoping to build a database app like the one in the screenie completely atop a Core Data foundation.

I'll scour the web a bit to see if there're any solutions, but thanks a lot for your help, I'll keep it in mind incase I don't find anything. :)
Well I'm going to go on the Web and read up on Core Data, I'd love to see how it works and get it down good so I could use it towards my advantage.
 

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
slooksterPSV said:
Well I'm going to go on the Web and read up on Core Data, I'd love to see how it works and get it down good so I could use it towards my advantage.
Ya, I searched around a bit and found an amazingly detailed, simple, step-by-step tutorial from Apple. Every step is a video, so if there's part of it you're stuck on you can just watch that one part. Helped me figure it out!


Link
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.