简体   繁体   English

如何在不选择任何行的情况下从iPhone的表格视图单元中读取值

[英]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.

相关问题 如何从iPhone的“表格”视图中获取选定单元格的单元格值 - how to get the cell value of a selected cell from Table view in iPhone 来自iPhone的表格视图单元格值 - Table View Cell value from iphone 如何在表格单元格中有多个标签而不制作自定义表格视图 iphone - how to have multiple labels in table cell without making custom table view iphone 如何将值从表视图单元格传递到视图控制器 - how to pass the value from table view cell to view controller 如何在单行中管理多个标签但没有。 表格视图中的单元格取决于 iPhone SDK 中的数组。 - How to manages multiple lable in single row but no. of cell in table view depends on array in iPhone SDK. 如何在表格视图中进行单元格编辑而不对单元格的设计进行任何更改? - how to do the cell editing in the table view without making any changes in the design of the cell? 如何禁用单击选项或在iPhone中选择表格中的行? - How to disable the click option or selecting the row in a table in iphone? 如何从表单元格调用/传递数组值到视图? - How to call/pass an array value from a table cell into a view? 在选择表格单元格“ didSelect”时,如何将图像解析到另一个视图? - On selecting the table cell “didSelect” how to parse images to another View? 在选择器视图 iphone 中选择行时出错 - error while selecting row in a picker view iphone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM