可可数据库结果 [英] Database Results in Cocoa

查看:49
本文介绍了可可数据库结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个必须与服务器数据进行交互的应用程序,然后相应地显示来自数据库的结果.我正在用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.

示例:用户登录到Web应用程序.他们有一些提交网络报告的选项.选择:单行和多行.他们可以为要输入的各种变量选择这些字段中的多少个.然后将其保存在MYSQL数据库中,以备后用.

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.

示例(第2部分):客户端应用程序获取MYSQL数据库中的数据,然后显示它们.问题在于它是可变数量的字段和可变数量的类型.

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.

换句话说,数据库基本上存储了我们是否要显示NSSecureTextField,NSTextField等,然后将其显示在屏幕上.正如我在上面指出的那样,问题在于允许他们选择想要的元素的数量和类型-因此我不确定如何将其转换为代码.

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.

为了澄清,我不尝试构建在线Interface Builder.这是一种在线输入数据的方式,它具有可变数量的字段以及这些字段的各种类型.我已经创建了在线系统,但是在客户端部分遇到了困难.

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.

任何帮助将不胜感激!

推荐答案

我不确定我是否理解您的要求.弄清楚用户想要多少个NSTextField,然后有一个for()循环来创建它们,这不是很简单吗?您可能想要跟踪文本字段,所以我可能会这样:

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.

或者,您可以强制NSMatrix为您自动化布局.

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

如果您正在为iPhone编写客户端应用程序,那么我强烈建议您查看

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.

这篇关于可可数据库结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆