2015-03-02 28 views

回答

4

WatchKit表格沒有章節或標題,頁腳,或編輯或搜索,或數據源或代表。

+0

長呼吸.. AAAhhh sighhh – 2017-05-16 13:03:56

16

WKInterfaceTable不像UITableView那麼靈活,但是您可以使用不同的行類型手動創建行。並根據其類型填寫每個單元格的內容。

查看文檔:

Apple Watch Programming Guide: Tables

WatchKit Framework Reference: WKInterfaceTable

例如,讓我們創建表有兩個行類型:

  • headerRowType
  • detailRowType

    #define type1 @"HeaderRowType" 
    #define type2 @"DetailRowType" 
    
    // You also must create two classes: HeaderRowType and DetailRowType - controllers for these two types 
    
    // preparing datasource: fill rowTypes and tableObjects 
    NSArray* rowTypes = @[type1, type2, type2, type2, type1, type2, type2]; // types for table with 1 header cell and 3 detail cells in first "section", 1 header and 2 detail cells in second "section" 
    
    // set types! self.someTable - WKInterfaceTable, associated with table in UI 
    [self.someTable setRowTypes:rowTypes]; 
    
    for (NSInteger i = 0; i < rowTypes.count; i++) 
    { 
        NSString* rowType = self.rowTypes[i]; 
        if ([rowType isEqualToString:type1]) 
        { 
         // create HeaderRowType object and fill its properties. There you also can parse any data from main iPhone app. 
         HeaderRowType* type1Row = [self.someTable rowControllerAtIndex:i]; 
         // type1Row.property1 = ...; 
    
        } 
        else 
        { 
         DetailRowType* type2Row = [self.someTable rowControllerAtIndex:i]; 
         // type2Row.property1 = ...; 
         // type2Row.property2 = ...; 
        } 
    } 
    

完成!發揮你的想象力並創建更復雜的數據結構。

+0

如果你只是想要一個頭,只要將一個帶有標籤的組拖放到它上面,並將它放在WKInterfaceTable上方,它就可以正常工作。 – GeneCode 2016-08-24 10:15:32

0

TableKit在WatchKit API中不可用。但部分僅僅是一組額外的頁眉/頁腳意見細胞,可以通過使用定製設計的細胞來模擬:

WatchKit table with simulated sections

我創建簡單WKInterfaceTable extensions,來幫助管理表。下載Sample app