Need help with bindings in my new college app!

Discussion in 'Mac Programming' started by Littleodie914, Aug 8, 2006.

  1. macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #1
    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!
     

    Attached Files:

  2. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    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.

    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.
     
  3. macrumors regular

    Joined:
    Jun 4, 2006
    Location:
    B-Town, India
    #3
    Totally off topic, but Littleodie914, is your icon from a Postal Service single?
     
  4. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #4
    Yep :cool:
     
  5. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #5
    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
     

    Attached Files:

  6. macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
    #6
    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.
     
  7. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #7
    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. :)
     
  8. macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
    #8
    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.
     
  9. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #9
    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
     

Share This Page