如何从 UITableView 的每一行读取数据/测试? [英] How to read data/test from each row of a UITableView?

查看:23
本文介绍了如何从 UITableView 的每一行读取数据/测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 iOS 应用程序中,用户应该填写表格中的所有字段,其中每行可能包含:

In my iOS app the user is supposed to fill in all fields in a table where each row may contain a:

  • 文本视图,或
  • 日期选择器或
  • 选择器视图,或
  • 一个开关.

我创建了 7 种不同类型的单元格,每种单元格都包含具有特定标签的 UI 组件之一.通过这种方式,我可以在表仅处于读取模式"时访问它们.

I have created 7 different types of cell each of which contains one of those UI components with its specific tag. In this way I can access them when the table is only in "read mode".

单元格的最后一行包含一个保存"按钮.当按下时,所有这些值应该一起收集到一个对象中,该对象将存储在数据库中.

The last row of the cell contains a "Save" button. When pressed, all these values should be collected together into an object which will be stored in a database.

问题是我不知道如何从每一行读取这些内容.有具体的方法吗?

The problem is that I don't know how to read those things from each row. Is there a specific method?

推荐答案

要从您的单元格中获取所有数据,最好的方法是拥有一个 NSArray 来包含您需要的所有数据,并更新NSArray 中的这些值用于单元格中的相应数据.您必须使用某种 dataSource 来显示 tableView 中的数据,并且您可以使用该确切的 NSArray 来更新值并保存到只需通过它并保存这些值.

To get all data from your cells best way would be to have an NSArray that will have all the data you need, and update these values in NSArray for corresponding data in the cells. You have to use some kind of dataSource to show the data in the tableView and you can use that exact NSArray to update values and on save to simply go through it and save these values.

对于其他问题:@NickCatib 1) 我不明白 func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) 方法是做什么的.是否用于从每个单元格获取数据?什么时候叫?(换句话说,我如何将它链接到提交按钮的 IBAction)

For the other questions: @NickCatib 1) I don't understand what the method func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) does. Is it used to get data from each cell? When is it called? (in other words how can I link it to the IBAction of the submit button)

当您选择特定单元格时会调用该方法.您可以使用 selectRowAtIndexPath:animated:scrollPosition: 方法链接它.

That method is called when you select particular cell. You can link it with selectRowAtIndexPath:animated:scrollPosition: method.

@NickCatib: 2) 当提交按钮被点击时,为每个单元格分配一个唯一的标签来读取数据是否更好?

@NickCatib: 2) is it better to assign to each cell an unique tag to read the data when the submit button is touched?

你可以,但同样,更好的方法是如上所述迭代 NSArray.

You can, but again, better way would be to iterate thourgh NSArray as mentioned above.

这篇关于如何从 UITableView 的每一行读取数据/测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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