Balázs Vincze
Balázs Vincze

Reputation: 3832

WatchKit table numberOfRows returns 0

I have simple table in my WatchKit test application with just a label per TableRowController. When I try to set the text for the labels, I can not loop through the rows of the table view because table.numberOfRows returns 0.

However calling [self.table setNumberOfRows:x withRowType:@"RowController"]; the number of rows gets set to whatever number x is. This confirms that the IB reference to self.table is working.

What could be the problem?

Here is my code:

- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];

    // Configure interface objects here.

    [self configureTableWithData];
}

- (void)willActivate {
    // This method is called when watch view controller is about to be visible to user

    [super willActivate];
}

- (void)didDeactivate {
    // This method is called when watch view controller is no longer visible
    [super didDeactivate];
}

- (void)configureTableWithData {
    [self.table setNumberOfRows:1 withRowType:@"RowController"];
    NSLog(@"%i",self.table.numberOfRows);
    for (NSInteger i = 0; i < self.table.numberOfRows; i++) {
        TableRowController* theRow = [self.table rowControllerAtIndex:i];
        [theRow.timeLabel setText:@"Hello!"];
    }
}

Upvotes: 1

Views: 67

Answers (2)

user12425014
user12425014

Reputation: 126

In Swift you have also to check if the module is valid for current WatchKit extension.

Upvotes: 0

Bal&#225;zs Vincze
Bal&#225;zs Vincze

Reputation: 3832

The problem was actually quite simple, but very hard to track down. It turns out that my TableRowController class was not target member of my WatchKit Extension, only my main app.

Upvotes: 1

Related Questions