Get row index of custom cell in UITableview(获取 UITableview 中自定义单元格的行索引)
问题描述
我正在开发一个 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 中自定义单元格的行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取 UITableview 中自定义单元格的行索引
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
