0

This feels like a strange question to ask, but I've not managed to find an answer in any Apple documentation, online articles on the topic, or example code from various third-party solutions I'm working with (like Realm), so I'd appreciate it if someone experienced in iOS development could help me figure this out.

In all UITableView tutorials, articles, and example code snippets in Apple's own documentation, the one and only showcased way of performing certain actions when a UITableViewCell's contents change is with the help of the following delegate method:

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)

However, it seems like this method only works for default UITableViewCells (rather than custom prototype cells with custom elements like UITextFields and UIImages) and relies on the use of the default delete/add buttons... unless I'm mistaken, which I very well could be.

So my question is: can this method also be used to work with custom prototype cells that use additional elements like UITextFields?

Or is there perhaps some other method for that?

Or is it, in fact, a matter of custom coding everything, e.g. a Did End On Exit IBAction for a custom text field in the cell?

Or am I altogether barking up the wrong tree, and I need to be looking into some kind of notification service that I need to setup?

I just can't shake the feeling that I'm missing some small but extremely vital aspect of working with custom table cells, so any insight would be much appreciated.

TL;DR: Need to know if there's a method or standard/common approach for detecting all possible changes to a custom table cell, i.e. when the text in a custom text field in the cell is edited and committed, when a cell is deleted, when a cell is added.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • It might help you to read the discussion in my online book, starting perhaps about here: http://www.apeth.com/iOSBook/ch21.html#_editable_content_in_table_items – matt Nov 24 '16 at 04:55

1 Answers1

0

The editingStyle delegate that you posted can be used for custom UITableViewCell and is mainly used for deletion. But be that as it may, there is an amazing tutorial on the Ray Wenderlich site that shows you how to "fake" the same behaviour for your own needs in case you need to add new buttons and offer more functionality. You can also set custom views and setup various actions. (Check out this post).

The only way to capture events like actions on UITextFields or UIButton or UITextView or any such thing is to set up appropriate delegate methods for the concerned event like textFieldDidBeginEditingor add a selector for the UIButton even if it is present inside a UITableViewCell. You will have to manage identifying which particular cell was editted by setting tags of the UIViewunder question to be the indexPath.row or some other logic that you find. (Apart from using a UITableViewController which allows you create outlets directly or IBAction for a particular UIButton.)

Hope this answers your query!

Community
  • 1
  • 1
Rikh
  • 4,078
  • 3
  • 15
  • 35