私はTableViewを持っています。私はUITableViewCellを持っています。 UItableViewControllerでは私はUITextFieldを持っています。 TextFieldをタップするときのアプリケーションです。それが開いています。 しかし、メソッド - tableView:willSelectRowAtIndexPath: - tableView:didSelectRowAtIndexPath:行に直接タップしないので、動作しません。 現在の行のindexPath.rowをどのように知ることができますか?UITableView with Custom UITableViewCell
1
A
答えて
0
cellForRowAtIndexPath
方法では、それを設定することで、あなたのUITextField
に現在の行を割り当てるには、indexPath.rowの値にタグプロパティをだ
[yourTextfield setTag:indexPath.row];
テキストフィールドが編集を終えたとき、あなたはそれのTagプロパティとあなたを読み出すことができますやり直し
0
あなたがいずれかを実行できます。
サブクラスUITextFieldですし、それにindexPathプロパティを与えます。 cellForRowAtIndexPathでは、textFieldを作成してセルに追加するときにプロパティを割り当てます。次に、textFieldデリゲートメソッドでは、正しいindexPathにアクセスできます。このメソッドでは、必要に応じて他の情報をtextFieldに関連付けることもできます。
はUicontrolののアクションメソッドを使用します。
- (void)textFieldDidChangeValue:(id)sender withControlEvents:(UIEvent *)event { NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: [[[event touchesForView:sender] anyObject] locationInView:self.tableView]]; //Do whatever you need to, now that you have the indexPath }
このメソッドは、サブクラスに必要なくなります。
+0
ご協力いただきありがとうございます。 – Anton
0
tableViewとtextFieldへの参照がある限り、このようなことはうまくいくはずです。セルも表示する必要があります:
UITableViewCell* tvc = (UITableViewCell*)[textField superview];
while (tvc != nil && ![tvc isKindOfClass: [UITableViewCell class]])
tvc = [tvc superview];
NSIndexPath* ip = [tableView indexPathForCell: tvc];
関連する問題
- 1. prepareForSegue of custom UITableViewCell
- 2. Swift PickerView with custom tableViewCell.xib
- 3. TTTableViewController with custom cell sample
- 4. NSUserNotification with custom soundName
- 5. $ mdDialog.confirm()with custom templateUrl
- 6. QScrollArea with custom QFrame
- 7. Ext.Ajax.request with custom enctype
- 8. SetWinEventHook with custom data
- 9. UITableView内のUITableViewCell
- 10. カスタムUITableViewCell、UITableViewとallowsMultipleSelectionDuringEditing
- 11. openCV RGB2Gray with custom weights
- 12. Firebase ListAdapter with custom object
- 13. Flask-Admin with Custom Security
- 14. C++:find()with custom == operator
- 15. UISegmentedControl with custom color:セパレータラインバグ
- 16. heapq with custom compare predicate
- 17. std :: string with custom allocator
- 18. ActionMailer with Custom Rake Task
- 19. Wordpress Sticky Posts with Custom Post Types
- 20. android mapview with custom wms tile provider
- 21. Yii 2 Select2 kartik with custom html
- 22. std :: atomic with custom class(C++ 11)
- 23. REST + Spring + POST with custom marshaller
- 24. Apache James Custom Mailet with Async Processing
- 25. フォークGitHubプロジェクトwith custom wiki
- 26. Algolia with Custom Magento Theme(Ultimo)
- 27. iOSのUITableViewCell内のUITableView
- 28. は--- UITableViewCellの内側のUITableView、
- 29. MagicalRecord with UITableView例
- 30. Swift UITableView with Tabbar
タグは別のタグを使用する必要があるか、テーブルビューに複数のセクションがある場合のみ問題です。 – GendoIkari
良い点。 @Anton:これを考慮する必要があります。しかし、私には、彼が複数のセクションを持っているのか、何かのためにタグプロパティを使っているのかどうかは明らかではありませんでした。 –
ありがとうございました。できます! – Anton