building dynamic interfaces in Xcode apps

Discussion in 'Mac Programming' started by ZacharyDenison, Feb 27, 2008.

  1. macrumors newbie

    Feb 27, 2008

    I am trying to build an application in xcode that would allow me to request information from the user in a type of form (similar to an HTML form). The problem is that I don't know the fields until runtime. How can I generate the GUI (text boxes, buttons, radio buttons etc..) from dynamic information at run time. For example -- at run time i will parse a file that contains "Name, Address, Zip Code ... etc" and from that I want to generate the gui and have people enter the information -- ?

    Thank you.

  2. Moderator emeritus


    Jun 15, 2000
    Xcode is just an IDE. It can be used with Java, C, C++, Objective-C, AppleScript, etc. You need to be more specific on what language/API you're using.
  3. thread starter macrumors newbie

    Feb 27, 2008
  4. Moderator emeritus


    Jun 15, 2000
    Well you'll need to familiarize yourself with controls and creating them on the fly. Read the docs on NSView, NSTextField, and NSButton.

    Parsing the file will vary depending on the file format. Easiest way is to use a plist and read it in as an NSDictionary/NSArray. But you could also use XML.
  5. thread starter macrumors newbie

    Feb 27, 2008

    that was basically my question, how to create those elements on the fly.
  6. Moderator emeritus


    Jul 24, 2002
    This code would create an NSTextField and add it to the content view of a window:

    -(void) addTextFieldToWindow:(NSWindow *) window inFrame:(NSFrame) frame
      NSTextField *field = [[NSTextField alloc] initWithFrame:frame];
      [field autorelease]; // This assumes you are not using garbage collection
      [[window contentView] addSubview:field];
    Note that this does not ensure that the added view is visible! I would imagine that you would actually want to specify the view you are adding it to. I would have thought you would be using a NSScrollview to contain your content so you would actually add the view to the document view of the scroll view...

Share This Page