问题描述
我正在开发一个 ipad 应用程序.我在应用程序中有一个 UITableview.UITableview 以编程方式创建,其中一个标签和 textview 作为其子视图.表格视图中最多可以有五行.一次向用户显示 2 行.在运行时,它需要在 textview & 中输入一些文本.将其保存在本地 sqlite 数据库中.我已经在代码中实现了 textViewDidBeginEditing 和 textViewDidEndEditing 委托.在 textViewDidEndEditing 委托中,我试图在 NSMUtable 数组中添加/替换文本(在 textview 中输入).为此,我输入文本的文本视图的行索引是必需的.这样我就可以添加/替换数组中的相应行索引.
I'm developing an ipad app. I have a UITableview in the app. The UITableview is created programatically with one label and textview as its subview. There can be a max of five rows in tableview. At a time 2 rows are displayed to the user. In runtime, its require to enter some text in the textview & save it in the local sqlite db. I have implemented the textViewDidBeginEditing and textViewDidEndEditing delegates in the code. In the textViewDidEndEditing delegate, Im trying to add/replace the text(entered in textview) in an NSMUtable array. For that the rowindex of the textview for which I enter the text is required. So that i can add/replace the respective row index in the array.
请告诉我如何获取文本视图的行索引.
Please let me know how to get the row index of the text view.
推荐答案
您的 TextView
将包含在某种单元格中.找到此单元格后,您可以向表格索取索引.从您的 TextView
向上导航到视图层次结构以找到单元格.例如:
Your TextView
will be contained within some kind of cell. Once you have found this cell, you can ask the table for the index. Navigate from your TextView
up the view hierarchy to find the cell. For example:
TextView* textView = // your textView;
UITableViewCell* cell = (UITableViewCell*)[textView superview];
UITableView* table = (UITableView *)[cell superview];
NSIndexPath* pathOfTheCell = [table indexPathForCell:cell];
NSInteger rowOfTheCell = [pathOfTheCell row];
NSLog(@"rowofthecell %d", rowOfTheCell);
这篇关于获取 UITableview 中自定义单元格的行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!