Sunday, 6 August 2017

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


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

Update tags of UItableViewCell without reloading whole UITableView:

In iOS app development, UITableView is most common control used in all apps. While creating list in iOS apps, we use UITableView, and if we want to delete a row from that UITableView when user tap on a button e.g. a delete button on the 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 ma talking about the 2nd option in order to update button tags 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 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 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,

No comments:
Write comments