Question

using a UITableViewController, where I am displaying some products which are sorted based on make year. Whenever user taps in a row (each row represents a single product) a new view gets displayed to edit the same product.

So after save if the user has changed the make year then it should display in main table view at appropriate place (i.e. sorted again accordingly). To accomplish this I am calling sort() method in.... here sort method returns NSMutableArray type of object.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Sort the records based on number of days.
    sortedProducts = [DTOConverter sort:unsortedProducts];

    return [sortedProducts count];
}

But the problem is that in table view I am still having the old values in that particular row until I bounce the entire view then it gets populated with new updated values.

Same thing happens in case of a new product gets added. Please correct me where I am doing wrong, I am sure that the issue might be related to indexPath, but i do not know how to tackle it. Please help.Thanks.

Was it helpful?

Solution

To update tableview data call

[tableView reloadData];

OTHER TIPS

You have to refresh the table or the individual row with one of the following methods:

  • reloadData
  • reloadRowsAtIndexPaths:withRowAnimation
  • reloadSections:withRowAnimation
  • reloadSectionIndexTitles

See the documentation on each method: UITableView Class Reference

Note: if you are only updating one row, do not call [tableView reloadData]. It is not necessary to reload all of the data in the table.

You may have to set up a delegate in the new view you are loading from your tableview and then set up your tableviewcontroller to implement the delegate method of that new viewcontroller. Then call reload data from that delegate method Here is an example of a delegate: Delegate example

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top