How to create partitions in WKInterfaceTable

How can we create partitions in a table since there is no delegate for this. And is there any other way to create partitions or should we use two tables.

+8
ios watchkit apple-watch wkinterfacetable
source share
3 answers

WKInterfaceTable is not as flexible as UITableView, but you can create rows manually using different types of rows. And fill in the contents for each cell according to its type.

See documentation:

Apple Watch Programming Guide: Tables

WatchKit Framework Link: WKInterfaceTable

For example, create a table with two row types:

  • 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 = ...; } } 

Done! Use your imagination and create more complex data structures.

+16
source share

WatchKit tables have no sections or headers, no footers, no editing, no search, no data sources, no delegates.

+4
source share

Table sections are not available in the WatchKit API. But a section is just a group of cells with additional header / footer views that can be modeled using custom cells:

WatchKit table with simulated sections

Ive created a simple WKInterfaceTable extension that helps manage tables. Download the sample application .

0
source share

All Articles