Setting up a TTSectionedDataSource

 

 


I am trying to create a TTTable with multiple sections. I have everything laid out inside of an array that looks a little something like this.

                       @"Styles",

                       [TTTableTextItem itemWithText:@"Styled Views" URL:@"tt://styleTest"],

                       [TTTableTextItem itemWithText:@"Styled Labels" URL:@"tt://styledTextTest"],

 

                       @"Controls",

                       [TTTableTextItem itemWithText:@"Buttons" URL:@"tt://buttonTest"],

                       [TTTableTextItem itemWithText:@"Tabs" URL:@"tt://tabBarTest"],

                       [TTTableTextItem itemWithText:@"Composers" URL:@"tt://composerTest"],

How do I put these values inside of my data source. I've tried:

self.dataSource = [TTSectionedDataSource dataSourceWithArrays:myArray]; 

However that seems to make my application crash.

 

 

2 Answers



 

 

Personally, I use [TTSectionedDataSource initWithItems:sections:], where items is an array containing per-section arrays of TTTableItems. E.g.:

NSAutoreleasePool* localPool = [[NSAutoreleasePool alloc] init];

NSMutableArray* items = [[NSMutableArray alloc] init];

NSMutableArray* sections = [[NSMutableArray alloc] init];

 

// Styles Section

[sections addObject:NSLocalizedString(@"Styles", @"Styles")];

NSMutableArray* itemsRow = [[NSMutableArray alloc] init];

[itemsRow addObject:[TTTableTextItem itemWithText:@"Styled Views" URL:@"tt://styleTest"]];

// Add more 'Styles' rows here...

[items addObject:itemsRow];

TT_RELEASE_SAFELY(itemsRow);

 

// Controls Section

[sections addObject:NSLocalizedString(@"Controls", @"Controls")];

itemsRow = [[NSMutableArray alloc] init];

[itemsRow addObject:[TTTableTextItem itemWithText:@"Buttons" URL:@"tt://buttonTest"]];

// Add more 'Controls' rows here...

[items addObject:itemsRow];

TT_RELEASE_SAFELY(itemsRow);

TTSectionedDataSource* ds = [[TTSectionedDataSource alloc] initWithItems:items sections:sections];

 

// Cleanup

TT_RELEASE_SAFELY(items);

TT_RELEASE_SAFELY(sections);

[localPool drain];

l

你可能感兴趣的:(UP)