1

I have a WKInterfaceTable with a single row controller. I am using the following code to bind data to the table:

[self.table setNumberOfRows:[data count] withRowType:@"RowController"];
for (int i = 0; i < [data count]; i++)
{
    RowController *row = [self.table rowControllerAtIndex:i];
    [row bind:[data objectAtIndex:i]]; // sets labels in the row etc.
}

I have the same problem if I add rows one-by-one using insertRowsAtIndexes:withRowTypes:. In either case, you have to first add a row to the table before you can update the row to show the correct data.

The first issue is that, because of this, the user gets to see the dummy storyboard data in between the row being added and the data being bound to it.

I've tried

  • hiding the group containing the table until the loop is finished, but then the first table item on first load ends up as if it were bound entirely to nil (even though it isn't) (someone else has seen this)
  • hiding the group containing each row's content until the group is finished, but the scroll handles this poorly and the rows pop in poorly
  • pushing the table out of view with another group until the loop is finished, but you can still scroll down to it

Is there really no way to render a table row before displaying it to the user?

Community
  • 1
  • 1
Rawling
  • 49,248
  • 7
  • 89
  • 127
  • Is your `bind` method doing anything time consuming asynchronously? – Mike Pollard Apr 27 '15 at 16:06
  • Nope, all the time-consuming asynchronous stuff happens before the `bind`... Is that a problem? – Rawling Apr 27 '15 at 17:13
  • No that's a good thing. Which method have you implemented this in? init or awakeWithContext? – Mike Pollard Apr 27 '15 at 17:39
  • It's in `awakeWithContext`. My controller is awoken, displays a splash screen, and makes a sequence of asynchronous HTTP requests, the last of which sets data to the table and shows it. – Rawling Apr 28 '15 at 06:37
  • Have your tried to bind your data also inside this method '- (id)contextForSegueWithIdentifier:(NSString *)segueIdentifier inTable:(WKInterfaceTable *)table rowIndex:(NSInteger)rowIndex' ? I'm doing both and not facing that issue. Maybe it could help somehow. – DevAndArtist Apr 28 '15 at 14:49
  • @DevAndArtist I don't have an interactive table anywhere in my storyboard so I can't really use that :p – Rawling Apr 29 '15 at 06:48

1 Answers1

3

I had a similar problem, which was solved by dispatching a job onto the main thread.

dispatch_async(dispatch_get_main_queue(), ^{
    [self.table setNumberOfRows:[data count] withRowType:@"RowController"];
    for (int i = 0; i < [data count]; i++)
    {
        RowController *row = [self.table rowControllerAtIndex:i];
        [row bind:[data objectAtIndex:i]]; // sets labels in the row etc.
    }
});
Matthew
  • 1,363
  • 11
  • 21
  • Hi Matthew, thanks for the answer; unfortunately we've shipped and I no longer have a watch to work with so I can't try it out! But I'll definitely give it a go (or pass it on) next time we work on the app, and hopefully this answer might help out someone else with the same issue. – Rawling Jun 02 '15 at 06:57
  • 1
    For anyone wondering: I tested this, and it works perfectly. Thanks Matt! – Edwin Finch Dec 05 '17 at 23:35