Faisal Syed
Faisal Syed

Reputation: 4471

Populating TableView in WatchKit Error

This is how I currently populate my table view in WatchKit:

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

    // Configure interface objects here.

    menuItems = [[NSMutableArray alloc] initWithObjects:@"Pizza", @"Chicken", @"Bread", nil];

    for (NSString *item in menuItems)
    {
        MenuRowController *menuRow = [myTableView rowControllerAtIndex:[menuItems indexOfObject:item]];
        [menuRow.menuItemLabel setText:item];
    }
}

I get the following error:

Extension[980:19597] Error - attempt to ask for row 0. Valid range is 0..0
Printing description of item:
Pizza
2015-07-05 01:58:07.284 ScanBarWatch WatchKit Extension[980:19597]    Error - attempt to ask for row 1. Valid range is 0..0
2015-07-05 01:58:14.780 ScanBarWatch WatchKit Extension[980:19597] Error - attempt to ask for row 2. Valid range is 0..0

I tried looking up this error online for a couple of hours but to no avail. No one seems to have a solution.

Upvotes: 4

Views: 723

Answers (2)

fredpi
fredpi

Reputation: 8962

Try to set the number of rows of the table:

[self.tableView setNumberOfRows:[menuItems count] withRowType:@"MenuRowController"];

Upvotes: 6

johndpope
johndpope

Reputation: 5257

In my case, error came from a copy and paste problem in IB - the Module being used was from the other project.

  • enter image description here

Updating this fixed issue.

enter image description here

Upvotes: 4

Related Questions