How can I reload the data in a WatchKit tableview?

reload tableview swift 4
tableview not reloading data swift
tableview reloaddata not refreshing
how to know uitableview has finished reloading data
update uitableview without reloaddata
tableview reloaddata not working swift 4
uitableview reload cell
reload tableview from another viewcontroller swift

I have an app for iPhone with a Tableview, whose data comes from CoreData.

The same data are also displayed in a watch app:

If I add a row from the iPhone app:

and I reload data in the Watch app:

I see the old rows empty!

If the stop the watch app and I start it again, everything appears correctly!

This is the code to fill the Tableview in the watch app

    [super awakeWithContext:context];
       [self loadTable];

    NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Data"];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Data"
    [fetchRequest setEntity:entity];

    NSSortDescriptor *sortByDate = [[NSSortDescriptor alloc] initWithKey:@"sortedDateAndTime" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortByDate, nil];
    [fetchRequest setSortDescriptors:sortDescriptors];
    self.watchMArray = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];

  //  [self.watchTableView setRowTypes:self.watchMArray];
    [self.watchTableView setNumberOfRows:self.watchMArray.count withRowType:@"data"];

    for (NSInteger i = 0; i < self.watchMArray.count; i++)
        WatchTableCell *cell = [self.watchTableView rowControllerAtIndex:i];
        NSManagedObject *data = [self.watchMArray objectAtIndex:i];
        dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
            //Background Thread
            UIImage *foto =[self loadImageFromData:[data valueForKey:@"imageData"]];
            dispatch_async(dispatch_get_main_queue(), ^(void){
                //Run UI Updates
            [cell.watchImage setImage:foto];
            [cell.watchDate setText:[NSString stringWithFormat:@"%@", [data valueForKey:@"dataEOra"] ]];

This is the code I am currently using to reload it:

- (IBAction)reloadTable {        
    [self loadTable];

Where am I wrong?

In the link @leolobato posted, there is actually a workaround. It did solve my problem.

when you change your rows just set them to =@"" first.

For example, if your row has a row.Label and you are changing it, do row.Label.text = @"" then again right after row.Label.text =@"[Actual text]"

ios - How can I reload the data in a WatchKit tableview?, I have an app for iPhone with a Tableview, whose data comes from CoreData. enter image description here. The same data are also displayed in a watch app:. I do believe you have to do two things simultaneously in order to achieve same result of tableview.reloadData() iOS function , so to reload a table in the watch with newly data do the following : 1-call table method :setNumberOfRows 2-loop through the rows refreshing values .

Calling the setRowTypes: or setNumberOfRows:withRowType: method.

Below is a statement from the developer document, I believe this will work.

When you want to update the contents of a table, call setRowTypes: or setNumberOfRows:withRowType: again with the new row type information. Calling these methods again forces the table to discard the old rows and create new ones. To insert new rows without removing the old ones, use the insertRowsAtIndexes:withRowType: method.

Link to document

How can I reload the data in a WatchKit tableview?, I have an app for iPhone with a Tableview, whose data comes from CoreData. enter image description here. The same data are also displayed  Reloading a row causes the table view to ask its data source for a new cell for that row. The table animates that new cell in as it animates the old row out. Call this method if you want to alert the user that the value of a cell is changing.

I've discovered that calling setNumberOfRows:rowType does not refresh the table unless you call it from the willActivate method. I had a delegate method that I was calling from a modal controller which would fetch a new set of records from the parent app and then reload the table. Even though printing out numberOfRows showed the new number of rows that I set, visually the existing rows were still displayed on screen. It was only after I set a flag in my delegate method and then in willActivate checked that flag and only then reloaded the table, did it refresh the display.

reloadData(), Reloads the rows and sections of the table view. Call this method to reload all the data that is used to construct the table, including cells, section headers and  Hi i retrieve data from a data base with a model and then it is displayed with a tableview. i have a button witch delete the selected row from the tableview. When i click on it, the row is deleted from the database but no from the tableview. So witch function can i use to reload the data in the tableview?

To reload the data, change your IBAction to:

- (IBAction)reloadTable {
    [self.watchTableView setNumberOfRows:self.watchMArray.count withRowType:@"data"];

From Apple's developer documentation on WKInterfaceTable:

This method removes any existing rows from the table and configures a new set of rows based on the information in the numberOfRows and rowType parameters.

Given you are using setNumberOfRows:withRowType: in your original code, I have used that here. The method setRowTypes: also achieves the same effect.

WKInterfaceTable, Define a custom data class to manage the contents of each row type. Tell the table object how many rows (and of what type) to display at runtime. Use instances of  The WatchKit framework provides the infrastructure for creating watchOS apps. All watchOS apps must have an extension delegate that you can use to respond to your app’s life cycle events. You can also use the delegate to manage background tasks, extended runtime sessions, Siri intents, workout sessions, or Handoff activity

For watchOS 5.1, iOS 12.1 it only worked if I added the setNumberOfRows:withRowType: in didAppear method. Using the awake(withContext:) or willActivate did not work for me. The first 4 rows were blank.

Swift Watchkit: How to Add Simple Dynamic Tables to Apple Watch , Like UITableView , the typical data for a WKInterfaceTable is an array. I'm making a simple constant array for this of my pace measured in  Use cases. TableView is useful when: presenting a list of settings, collecting data in a form, or. showing data that is presented differently from row to row (e.g. numbers, percentages and images). TableView handles scrolling and laying out rows in attractive sections, a common need for the above scenarios.

Swift WatchKit: Selecting, Deleting and Adding Rows in an Apple , Based on some pace data when I ran the Hot Chocolate 15K, we displayed the pace I ran at the mile splits. In a real Swift WatchKit: Selecting, Deleting and Adding Rows in an Apple Watch Table. Posted on swipe to the left to show the table view: The code reloads the array into the data property. TableView. TableView.jl is an ag-grid based table viewer built on WebIO.jl.It can display arbitrarily large tables by lazy-loading additional data when scrolling (this is the default for datasets with more than 10k rows).

Make a Table in watchOS Using WKInterfaceTable, To configure the contents of a UITableView , you set a delegate and data source and give the table information when it requests the number of rows and the row  I am using below code to populate tableview rows. On clicking a row I am reloading table data but row is not being updated. Before iOS 11 it was working fine but after updating to iOS 11 I am facing this issue:

How to reload a UITableView while preserving selections, When you call reloadData() on a UITableView it will refresh all cells from your data source, but it will also lose any selections the user has made  This video covers handing the 32 S&W from start to finish and includes a range report. It is long!!!!! Feel free to fast forward if needed.

  • Hard to tell. I'd want to run through that code in LLDB, which would almost certainly be useful.
  • since WatchOS2.0 released, may I know how do you manage to do the same thing (coredata across iOS and watchOS data consistency) now?
  • With watchOS 2 coredata is a big big problem !!
  • @Ragazzetto yes, I have been thinking of the solutions and none of them is perfect to make the data consistent on watchOS2.0
  • It's your post led me to this post and solved my problem, so thank you :)
  • This is a good workaround that works, this was driving me crazy for hours. Seems to be a bug in the Beta which they'll fix hopefully.
  • Has this bug been fixed in the GM version?
  • as you can see from the code in the method loadTable there is already a method call [self.watchTableView setNumberOfRows: self.watchMArray.count withRowType: @ "date"];
  • Technically it should work with only single line of code, mentioning the setRowTypes. I haven't tried, but I have read the document, thats why I send you.
  • Thank you @JayahariV , I've use the Duncan code but in my case the change of the code has not solved the problem !! Now all rows are empty :-(
  • Is this still a bug in the current version after beta? I log what text I'm using in the labels when I do a reload, but its not changing what is in the table.
  • This is actually documented in the WKInterfaceController docs.