Search code examples
iosapple-watch

Table causing crash on Apple Watch


When I try to launch my apple watch app with the following code, it crashes after the log prints "produce" (there is nothing after that). When I remove the code, it does not crash. I cannot figure out what could be going wrong.

 NSMutableArray *rowTypesList = himo; //himo is a nsmutablearray that contains info from NSXMLParser
        [_table setRowTypes:rowTypesList];
        for (NSInteger i = 0; i < _table.numberOfRows; i++)
        {
            NSDictionary *itemAtIndex =(NSDictionary *)[himo objectAtIndex:i];
            NSObject *row = [_table rowControllerAtIndex:i];
            Cell *importantRow = (Cell *) row;
            [importantRow.label setText:@"hi"];
        }
NSLog(@"produce");

Solution

  • It looks like you are mixing your data you want to display in your table with the row controller type. If you just have a single row controller type of Cell which it appears you do by your code you want the following:

    [_table setNumberOfRows:[himo count] withRowType:@"theIdentiferYouGaveTheRowControllerInTheStoryboard"];
    for (NSInteger i = 0; i < [himo count]; i++) {
        NSDictionary *item = (NSDictionary *)[himo objectAtIndex:i];
        Cell *rowController = [_table rowControllerAtIndex:i];
        [rowController.label setText:@"hi"]; // you probably want to use the data from item here
    }