显示表格中文本字段的输入

发布于 2024-12-11 22:03:34 字数 492 浏览 0 评论 0原文

在我正在制作的应用程序中,我需要能够存储来自文本字段的输入,然后在表格视图中显示它们,并能够为用户删除或编辑输入,并添加更多内容。

我已经可以按下按钮 ->在下一个视图中,插入数字并选择所需的任何选项,然后按“添加”。但我不知道如何存储和显示输入。

该应用程序应该以这种方式工作:

您打开该应用程序,然后可以按加号。然后您将进入模态视图,其中可以从滑块中进行选择,并在两个文本字段中输入两个不同的数字。然后按添加。按下“添加”按钮后,您将进入第一个视图,您从滑块中选择的数字和选项将显示在表格视图中,下面还有另一个加号。所以你可以一遍又一遍地重复整个事情。

在上面之后,会有一个“计算”按钮,它计算不同的输入,并给出最终结果,但当我让基本的东西工作时,我会尝试自己弄清楚这一点。

我期待您的答复,并且希望您能彻底解释事情,因为我是这个领域的新手。

请不要只是将我重定向到,我已经读了很多,但没有任何内容涵盖了我的问题。而且我不太擅长根据苹果自己的参考库自己弄清楚事情。

In the app I'm making I need to be able to store input from textfields, then show them in a table view with the ability, for the user, to delete or edit the input, and add more.

I have already made it possible to press a button -> next view, insert numbers and choose whatever option you want, and then press ADD. But I have no idea how to store and show the input.

The app is supposed to work this way:

You open the app, and you can press a PLUS sign. Then you are taken to a modal-view where get the option to choose from a slider, and input two different numbers in two textfields. Then press ADD. After the ADD-button is pressed, you are then taken to the first view, and the numbers and option you chose from the slider are then shown in a table view, with yet another plus sign beneath. So you can repeat the whole thing over and over.

After the above, there will be a "Calculate" button, where it calculates the different inputs, and gives an end result, but I will try and figure that one out myself, when I get the basic stuff working.

I'm looking forward to your answers, and I hope you will explain things thoroughly, as I am new at this field.

And please, don't just redirect me to , I have read a lot, but nothing that covered my problem. And I'm not that good at figuring out things myself, based on e.g. Apple's own reference library .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

街道布景 2024-12-18 22:03:34

您将需要某种方式来存储所有这些信息。如果您需要以任何方式对其进行排序或查询,请使用 SQLite,或者您可以使用 Core Data,但我从来没有这样做过。

更简单的是,您可以实例化一个 NSMutableArray,并使其成为父视图的属性,当您推送子视图以添加信息时,添加一个保存信息的自定义对象,并将其添加到数组中。表与数组一起使用非常容易,然后实现表方法来重新排列和删除它们。

- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath

至于计算总数或其他什么,只需循环该数组中的所有对象,然后执行任何您需要的操作。

编辑:

自定义类的示例:

MyClass
@property (nonatomic, retain) NSString *infoString1;
@property (nonatomic, retain) NSString *infoString2;
@property (nonatomic) int sliderValue;

如何存储信息

MyClass *object1 = [[MyClass alloc] init];
object1.infoString1 = textField.text;
object1.infoString2 = textField2.text;
object1.sliderValue = [theSlider.value intValue] //Dont think thats correct code, but you get the idea
[parentView.theArray addObject:object1];
// then dismiss the view

You are going to need someway to store all that info. If you need to sort or query against it in any way, use SQLite or you could use Core Data, but I never have.

More simply, you could instantiate an NSMutableArray, and make it property of the parent view, and when you push the child view to add the info, add a custom object that holds your info, and add it to the array. Tables are quite easy to use with array's, then implement the table methods to rearrange and delete them.

- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath

As far as calculating out totals or whatever, just loop through all the objects in that array, and do whatever you need to.

EDIT:

Example of a custom class:

MyClass
@property (nonatomic, retain) NSString *infoString1;
@property (nonatomic, retain) NSString *infoString2;
@property (nonatomic) int sliderValue;

How you could store the info

MyClass *object1 = [[MyClass alloc] init];
object1.infoString1 = textField.text;
object1.infoString2 = textField2.text;
object1.sliderValue = [theSlider.value intValue] //Dont think thats correct code, but you get the idea
[parentView.theArray addObject:object1];
// then dismiss the view
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文