Beginner to Xcode and Cocoa

Discussion in 'Mac Programming' started by jbcandkc, May 24, 2015.

  1. jbcandkc macrumors member

    Nov 1, 2006
    Let me start with I'm a beginner with Xcode and Cocoa. I have fooled around with it on and off for years, doing small utilities for myself. Using Xcode 5.1.1 on Mavericks.

    I am working on a small program that uses Core Data. I have followed a tutorial and have everything working using bindings and an array controller. Now I am trying to polish it a bit and this is where I usually run into problems. I want to add a sheet so when you press the add button, instead of the table just adding a row and editing in the table, the window would present a sheet and you would enter your new data there.

    Now to question 1...
    I was able to make it work by subclassing the NSArrayController and overriding the add: method but also letting it act as an AppContoller as well, setting up IBOutlets to the sheet and window and making a closeSheet method to close the sheet. Is this the correct way to go about this? (See Question 2)

    Question 2...
    I don'd think this is the proper way to do this. I assume the proper way would be to make an AppController class, connect the add button to it, let the AppController present the Sheet and then ask the ArrayController to add a new record. Then the close button would tell the AppController to close the sheet. If this is the proper way, I am lost on how to call an ArrayController method from within my AppController.

    Thanks for any help.
  2. bjet767, May 28, 2015
    Last edited: May 28, 2015

    bjet767 macrumors 6502a

    Oct 2, 2010
    "I want to add a sheet "

    As with many coding questions there isn't enough information to figure out what you really want to do.

    Your questions seems to indicate you want some sort of pop-up view to appear when the add button is pushed and then use the array controller to manage the data.

    I'm sure many people will have an approach to this, but my first thoughts are you need to make an action for the add button and then in the method/function code a view linked to the array controller.

    Remember if you go beyond the simple key-value coding and linking you have to manually code the stuff.

    NSArrayController has a lot of methods/functions to accomplish your goals.

    What I am writing is this, you probably won't have to sub-class the array controller and good coding always lets the object be the object it was designed for. NSArrayController is designed to control arrays, not views. So if you need a new view within the current view use the view controller and add a method/function to it.

    I am a bit confused though, you mention an "appController" and that is what confuses me. Typically an OSX program has an AppDelegate and a ViewController and it is normally within the AppDelegate the CoreData code is put.

    Also I have found for small data based programs using a Document based method is far easier and more portable than CoreData. A Document based program can easily be sorted, key-value coded and made portable between OSX and iOS. I've even been able to develop portable Documents that code easily in MFC.

    Just some thoughts.

Share This Page