[英]how to read value from table view cell in iphone without selecting any row
thanks in advance i want to read cell value from tableview but without selecting any cell. 在此先感谢,我想从tableview中读取单元格值,但不选择任何单元格。 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. 然后稍后通过didselectedRowAtIndexPath例如,我选择第一个单元格值并将其放在另一个视图的标签中,并在我单击新视图上的保存按钮时将其更改为a,然后我的新值正确返回到表视图单元格的第一个视图中,这是所有操作正常工作。
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或任何其他方法中的任何单元格,而是在此视图上的保存按钮上读取此单元格值,并在读取此内容后值我再次将其保存在数据库中
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? 您肯定有某种数据结构(很可能是NSArray),该数据结构最初是用数据填充表的,对吗? 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? 为什么不只是从那里获取它,而不是将手套放在UITableViewCell上并深入其视图层次结构以找到所需的标签呢?
The didselectedRowAtIndexPath
method is just a means to tell you what point in your array to read data from. didselectedRowAtIndexPath
方法只是一种告诉您数组中从哪个点读取数据的方法。 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. 在viewDidLoad的末尾执行此操作将是适当的。
Try... 尝试...
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if its a custom cell use 如果它是自定义单元格使用
CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];
NSLog("%@", cell.property): NSLog(“%@”,cell.property):
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. 并且可以从该单元格中获得在创建单元格时必须指定的标签值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.