如何从iphone中的表格视图单元格中读取值而不选择任何行

时间:2022-12-03 10:19:00

thanks in advance i want to read cell value from tableview but without selecting any cell. let me explain first in my table view each cell have some value when tableview is drown fist time this all value is coming from database. then later through didselectedRowAtIndexPath for example i select first cell value and take it in label in another view and change it a when i click save button on new view then my new value is coming back in first view in table view cell correctly this all operation is correctly working.

在此先感谢我想从tableview读取单元格值,但不选择任何单元格。让我先解释一下在我的表视图中每个单元格都有一些值,当tableview被淹没时,这个值全部来自数据库。然后通过didselectedRowAtIndexPath例如我选择第一个单元格值并将其带入另一个视图中的标签并将其更改为当我在新视图上单击保存按钮然后我的新值将在表视图单元格中的第一个视图中正确返回此所有操作都是正确工作。

but my problem is that after changing some cell value i want to read all the data that display on table view cell but without selecting any cell in didselectedRowAtIndexPath or any other method i read this cell value on my save button on this view and after read this value i again save it in database

但我的问题是,在更改一些单元格值之后,我想要读取显示在表格视图单元格上的所有数据,但是没有选择didselectedRowAtIndexPath中的任何单元格或任何其他方法,我在此视图上的保存按钮上读取此单元格值,并在读取此内容后值我再次将其保存在数据库中

4 个解决方案

#1


5  

Geez, I think if I were you I'd go the other direction. You surely have a data structure of some sort (an NSArray, quite likely) that you used to populate your tables with data in the first place, right? Why not just get it from there, rather than getting your mitts on the UITableViewCell and digging into its view hierarchy to find the label you want?

吉兹,我想如果我是你,我会走向另一个方向。你肯定有一种类型的数据结构(非常可能是NSArray),你曾经用数据填充表格,对吗?为什么不从那里获取它,而不是在UITableViewCell上获取你的手套并挖掘它的视图层次结构来找到你想要的标签?

#2


1  

The didselectedRowAtIndexPath method is just a means to tell you what point in your array to read data from. You have to create an array of some sort to build the table from. If you know you want to read data from the first cell, simply read it directly from the array populating your table. Doing this at the end of viewDidLoad would be appropriate.

didselectedRowAtIndexPath方法只是告诉您数组中从哪个点读取数据的一种方法。您必须创建某种类型的数组来构建表。如果您知道要从第一个单元格读取数据,只需直接从填充表格的数组中读取数据即可。在viewDidLoad的末尾执行此操作是合适的。

#3


1  

Try...

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

if its a custom cell use

如果它是自定义单元格使用

CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];

NSLog("%@", cell.property):

#4


0  

You can get cell for only visible rows without clicking them as

您可以仅为可见行获取单元格而不单击它们

NSArray *visibleRowsArr = [tableView indexPathsForVisibleRows];

UITableViewCell *cell = [tableView cellForRowAtIndexPath:[visibleRowsArr objectAtIndex:0]];

and from this cell you can get values for a tag which you have to specify while creating a cell.

从这个单元格中,您可以获得在创建单元格时必须指定的标记的值。

#1


5  

Geez, I think if I were you I'd go the other direction. You surely have a data structure of some sort (an NSArray, quite likely) that you used to populate your tables with data in the first place, right? Why not just get it from there, rather than getting your mitts on the UITableViewCell and digging into its view hierarchy to find the label you want?

吉兹,我想如果我是你,我会走向另一个方向。你肯定有一种类型的数据结构(非常可能是NSArray),你曾经用数据填充表格,对吗?为什么不从那里获取它,而不是在UITableViewCell上获取你的手套并挖掘它的视图层次结构来找到你想要的标签?

#2


1  

The didselectedRowAtIndexPath method is just a means to tell you what point in your array to read data from. You have to create an array of some sort to build the table from. If you know you want to read data from the first cell, simply read it directly from the array populating your table. Doing this at the end of viewDidLoad would be appropriate.

didselectedRowAtIndexPath方法只是告诉您数组中从哪个点读取数据的一种方法。您必须创建某种类型的数组来构建表。如果您知道要从第一个单元格读取数据,只需直接从填充表格的数组中读取数据即可。在viewDidLoad的末尾执行此操作是合适的。

#3


1  

Try...

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

if its a custom cell use

如果它是自定义单元格使用

CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];

NSLog("%@", cell.property):

#4


0  

You can get cell for only visible rows without clicking them as

您可以仅为可见行获取单元格而不单击它们

NSArray *visibleRowsArr = [tableView indexPathsForVisibleRows];

UITableViewCell *cell = [tableView cellForRowAtIndexPath:[visibleRowsArr objectAtIndex:0]];

and from this cell you can get values for a tag which you have to specify while creating a cell.

从这个单元格中,您可以获得在创建单元格时必须指定的标记的值。