Prateek Chaubey
Prateek Chaubey

Reputation: 645

Value is shown in UITableView after it is scrolled

In my iPad application, I am inserting some value on a label. That value should also appear on a UITableView in another class. When I insert the value in the label and navigate to another view, there is no value appearing on the table view but when I scroll the table view up and as it comes to its original position, the value appears. How can I fix it?

Thanks and regards

PC

Upvotes: 0

Views: 187

Answers (2)

MystikSpiral
MystikSpiral

Reputation: 5028

When you scroll the table you are eventually reloading the data as things become visible. If you call [tableView reloadData] on viewillAppear this should get the label refreshed and displaying correctly for you.

Good Luck!

Upvotes: 1

Kyle
Kyle

Reputation: 14656

Check out the reloadData method in the documentation. You will need to call this method after changing the value so the table knows to reload the cells currently being displayed. As you scroll up the cells are being redrawn, which is why you see the new value after a scroll.

Just to clarify, the reloadData method will need to be called on the UITableView object.

[myTableView reloadData];

From the documentation:

Reloads the rows and sections of the receiver.

- (void)reloadData

Discussion

Call this method to reload all the data that is used to construct the table, including cells, section headers and footers, index arrays, and so on. For efficiency, the table view redisplays only those rows that are visible. It adjusts offsets if the table shrinks as a result of the reload. The table view's delegate or data source calls this method when it wants the table view to completely reload its data. It should not be called in the methods that insert or delete rows, especially within an animation block implemented with calls to beginUpdates and endUpdates

Upvotes: 1

Related Questions