Iphone 设置TTSECTIONEDDATASURCE

Iphone 设置TTSECTIONEDDATASURCE,iphone,sdk,three20,Iphone,Sdk,Three20,我正在尝试创建一个包含多个部分的TTTable。我把所有的东西都放在一个数组里,看起来有点像这样 @"Styles", [TTTableTextItem itemWithText:@"Styled Views" URL:@"tt://styleTest"], [TTTableTextItem itemWithText:@"Styled Labels" URL:

我正在尝试创建一个包含多个部分的TTTable。我把所有的东西都放在一个数组里,看起来有点像这样

                       @"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"],
如何将这些值放入数据源中。我试过:

self.dataSource = [TTSectionedDataSource dataSourceWithArrays:myArray]; 

然而,这似乎使我的应用程序崩溃

如果您将整个分配声明包括在内,这将很有帮助,例如

myArray = ... ;

我猜代码在赋值语句中的最后一个“]”之前缺少一个“,”nil“。

我个人使用
[TTSectionedDataSource initWithItems:sections://code>,其中
items
是一个数组,包含
TTTableItem
的每节数组。例如:

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

数组很好,它是通过一系列for循环创建的,我认为这会使问题看起来比实际更复杂。我不是问如何创建数组,因为这部分已经正确完成了。我问的是如何将该数组中的对象移动到self.dataSource中。在这种情况下,您需要在分配给self.dataSource的“];”之前加上一个“、nil”-注意,该方法称为“dataSourceWithArrays”(复数)!