Update UITableViewCell subviews tag

Update UItableViewCell subviews tag after deleting a row from UITableView in swift3 iOS tutorial

Update tags of UItableViewCell on deleting a row:

In this post we will learn, how to update UITableViewCell subviews tag without reloading whole UITableview. This scenario comes up in case where we have to delete a row from UITableView. So in order to update tags on UITableViewCell subview’s we have only one option that is to reload whole UITableView.

In iOS app development, UITableView is most common control used in all apps. While creating list in iOS apps, we commonly use UITableView. If we want to delete a row from a UITableView, for example  when user tap on a delete button. Example a delete button on the UITableviewcell row. Than at this time we have below options to full-fill our objective

1) remove the index based on our button tag from the data-source array
2) After removing the record, reload UITableView
3) use UItableView function deleteRows, reloadRows to load only that particular row

Now, first option is the necessary step, we always need to perform if we want to change or delete an item or row from UITableView. The main limitation of reloading whole UITableView, here i am talking about the 2nd option. In order to update button tags, reloading whole UITableView is not a good approach as if we have 100’s of records in our UITableView than they all will get reloaded. With 3rd option we will remove the limitation that we encountered in option  2nd, but it will only update the tag of row that gets reloaded again, thus left us with all old tags for button intact in other rows of UITableView.

Solution for update tag after deleting row form UITableView:

The only solution for update UItableViewCell subviews tag after deleting a row from UITableViewis is that to get the tag when we called our button action,  rather than giving the tag to button at cellForRowatIndexPath method. One can get the tag by using the below code.

In above code we get the point of our sender, and from that point we get the row index path.

Where to go from here:

In this tutorial, we learned how to update button tag displayed on UITableView cell while deleting or adding a row in the UITableView rather than reloading whole UITableView,