ioswatchkitwkinterfacetablewkinterfaceimage

WKinterfaceImage in table losing image when refreshed


I have a WKInterfaceTable in a WatchKit app. The rows in the table each have an image and a label. On first load of the interface controller, I set up the table either in awakeWithContext or willActivate, and everything works fine. The labels and images show their content as expected. But if I reload the table in response to the user selecting a row, all the images disappear.

I'm using setImageNamed: on the WKInterfaceImage to set an image that is in the WatchKit app bundle. I've tried having the image in the assets file and included in the project separately. What gives?

My code to set and reset the table looks like this:

[self.table setNumberOfRows:self.rowData.count withRowType:@"myRowType"];
for (NSInteger i = 0; i < self.table.numberOfRows; i++)
{
  MyRowClass row = [self.table rowControllerAtIndex:i];
  MyDataClass data = [self.rowData objectAtIndex:i];
  [row.label setTitle:data.title];
  [row.image setImageNamed:@"MyImage.png"];
}

Solution

  • There is a bug that should be fixed in the next beta. There is a workaround and it's to reset the value just before assigning the new one.

    Try this:

    [self.table setNumberOfRows:self.rowData.count withRowType:@"myRowType"];
    for (NSInteger i = 0; i < self.table.numberOfRows; i++) {
        MyRowClass row = [self.table rowControllerAtIndex:i];
        MyDataClass data = [self.rowData objectAtIndex:i];
        [row.label setTitle:data.title];
        [row.image setImageNamed:nil];
        [row.image setImageNamed:@"MyImage.png"];
    }