問題描述
我正在開發一個 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 中自定義單元格的行索引的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!