Database Results in Cocoa

I am creating an application that has to interact with server data and then display the results from a database accordingly. I am writing the client side app in Cocoa. Example: A user logs on to a web application. They have some options for filing a web report. Choices: single line and multiple line. They can choose how many of these fields they have for various variables that they want to input. This is then saved in a MYSQL database for later use. Example (part 2): The client side application fetches the data in the MYSQL databases and then displays it. The problem is that it is a variable number of fields and a variable number of types. In other words, the database basically stores if we want to display a NSSecureTextField, NSTextField, etc. and then displays that on the screen. As I pointed out above, the problem is that they are allowed to choose how many and the type of the element they want - so I am not quite sure how to transfer this to code. And just to clarify, I am not attempting to build an online Interface Builder. Simply a online way to input data which has a variable amount of fields, and various types of these fields. I have the online system created, but I am having difficulty with the client side part. Any help would be greatly appreciated!

individualtermite asked Jul 4, 2009 at 19:32 individualtermite individualtermite 3,715 16 16 gold badges 50 50 silver badges 80 80 bronze badges

1 Answer 1

I'm not sure I understand what you're asking for. Isn't it pretty trivial to figure out how many NSTextFields the user wants and then have a little for() loop to create them? You'll probably want to keep track of the textfields, so I would probably do it like this:

NSMutableDictionary * interfaceElements = [[NSMutableDictionary alloc] init]; for (NSInteger i = 0; i < numberOfTextFields; ++i) < //this is just to make a frame that's indented 10px //and has 10px between it and the previous NSTextField (or window edge) NSRect frame = NSMakeRect(10, (i*22 + (i+1)*10), 100, 22); NSTextField * newField = [[NSTextField alloc] initWithFrame:frame]; //configure newField appropriately [[myWindow contentView] addSubview:newField]; [interfaceElements setObject:newField forKey:@"someUniqueIdentifier"]; [newField release]; >

The dictionary of course would not be local to this method, but I think you get the idea.

Alternatively, you might be able to coerce NSMatrix into automating the layout for you.

If you're writing a client application for the iPhone, then I would highly recommend looking to the Settings Application Schema reference for inspiration. If you're unfamiliar with this, here's a brief introduction: The iPhone allows developers to move their preferences area from the actual app to the Settings app. This is done by creating a settings bundle and building a plist in a very specific way. Settings.app then discovers that plist, parses it, and builds an interface according to the definition it contains. You can do switches, textfields (even secure ones), sliders, groups, and a couple other kinds of interface elements.