haresh
haresh

Reputation: 496

What is More reliable way to reload UITableView Data?

I have found 2 functions to reload my rows of UITableView

1st.

    [tableView reloadRowsAtIndexPaths:[tableView indexPathsForVisibleRows] 
                 withRowAnimation:UITableViewRowAnimationNone];

2nd.

    [tableView reloadData];

What is more specific way to reload UITableView Data

Upvotes: 0

Views: 1676

Answers (2)

Hemang
Hemang

Reputation: 27072

This answer may have two cases,

a) You've the table with at least a single section (with a title or returning a view for section)

  • In this case, if you call reloadData then it'll also reload section too. But reloadRowsAtIndexPaths:withRowAnimation: will only reload the visible cells and not the section.

b) You've the table with at least a single section (without a title or returning a view for section)

  • In this case, if you call reloadData or reloadRowsAtIndexPaths:withRowAnimation: both will reload only the visible cells.

So which one is the better?

  • As I explained, based on the case, you should call any of the one method. If you have sections which you don't want to reload then you should call reloadRowsAtIndexPaths:withRowAnimation: method. Or if you want to reload cells along with section then should call reloadData method.

Upvotes: 1

jnpdx
jnpdx

Reputation: 52535

Both are "reliable" and possibly "specific" (depending on what you mean by specific) -- in fact, there are even more ways:

reloadData
reloadRowsAtIndexPaths:withRowAnimation:
reloadSections:withRowAnimation:
reloadSectionIndexTitles

Check the developer documentation (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/index.html) on the differences, but the short answer is that they are all reliable -- it just depends on how much information you want to reload, and if you want to do it with animation.

For example, if you only want to reload certain rows, you can use reloadRowsAtIndexPaths:withRowAnimation:. If you want to reload a whole section, use reloadSections:withRowAnimation:.

Upvotes: 1

Related Questions