endy
endy

Reputation: 3872

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.

Upvotes: 1

Views: 1234

Answers (2)

Greg Haines
Greg Haines

Reputation: 61

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];

Upvotes: 0

mrose17
mrose17

Reputation: 91

it would be helpful if you would include the entire assignment statement, e.g.,

myArray = ... ;

my guess is that the code is missing a ", nil" right before the final "]" in the assignment statement.

Upvotes: 3

Related Questions