Reputation: 1791
I have a TableViewController with 5 cells added dymanically at run time. The initial values of the cells(cell.detailtext.text) is some default value same for all cells. Now once the viewDidLoad is finished and even this is done : (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath, Now I need to update the cell values at runtime based on certail conditions. How do I update the cell values later?
In short I need to implement the below algo in a function in IOS
for each cell of tableView
cell.detailtext.text = @"new Value"
OR
func() {
cell = cell at index(passed to function)
cell.detailtext.text = @"new Value"(passed to function)
}
Upvotes: 1
Views: 3607
Reputation: 479
Modify the value that you need to display using this method
reloadRowsAtIndexPaths:withRowAnimation:
This reloads the Particular cell in the tableview.
Upvotes: 0
Reputation: 2642
When ever you update the dataSource for the UITableView u need to call reloadData
But that updates the entire table and has two issues:
1) If you have a large table and your just changing a single value its a large overhead
2) If you are animating your updates (additions or removals) this can lag your device with large amounts of data
check the Class Reference: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html
Alternatively if you are just updating individual cells try calling
reloadRowsAtIndexPaths:withRowAnimation:
It is much better performance wise, but has some limitations such as if you are adding large amounts of data it cant be applied.
I could go into more situations and detail but that would be going out of scope.
Upvotes: 2
Reputation: 1695
You have to modify your data by giving array values to your tableview. and then you have to use
[tableView reloadData]
method for update Data in tableview
Upvotes: 0