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

ZacharyDenison

macrumors newbie
Original poster
Feb 27, 2008
8
0
Hello,

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.

Zach.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
This code would create an NSTextField and add it to the content view of a window:

Code:
-(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...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.