2015-06-06 73 views
0

我正試圖在WatchKit上創建一個表。由於某些原因,該應用在WatchKit中啓動時只是空白。我已經確認這是一個表格問題(我添加了一個靜態標籤,並能夠看到它)。我相信我也擁有所有IBOutlets。我究竟做錯了什麼?WatchKit表空白

我有我的InterfaceController.h下面的代碼:

@interface InterfaceController : WKInterfaceController { 
    NSMutableArray *listArray; 
} 

@property (weak, nonatomic) IBOutlet WKInterfaceTable *playlistTable; 

InterfaceController.m:

- (void)awakeWithContext:(id)context { 
    [super awakeWithContext:context]; 
    // Configure interface objects here. 

    listArray = [[NSMutableArray alloc] initWithObjects:@"Hello", @"Watch", @"World", nil]; 
    [self setupTable]; 
} 

- (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)setupTable { 

    [self.playlistTable setRowTypes:listArray]; 

    for (int i = 0; i < self.playlistTable.numberOfRows; i++) 
    { 
     universalRow *row = [self.playlistTable rowControllerAtIndex:i]; 
     [row.mainTitle setText:[listArray objectAtIndex:i]]; 
     [row.subtitleLabel setText:@"subtitle!"]; 
    } 
} 

和NSObject的行級 'universalRow':

@interface universalRow : NSObject { 

} 

@property (nonatomic, weak) IBOutlet WKInterfaceLabel *mainTitle; 
@property (nonatomic, weak) IBOutlet WKInterfaceLabel *subtitleLabel; 

@end 

回答

1

原來我沒有在故事板中設置我的行控制器的標識符。一旦我做到了,它就按預期工作。

enter image description here

1

setRowTypes:需要一個字符串數組,每個名稱都分配給故事板中的行控制器d,而不是你要放入該行的數據。

您可能想要[self.playlistTable setNumberOfRows:listArray.count withRowType:@"RowType"]其中@"RowType"是您在故事板中給予您的行控制器的任何名稱。