Skip to content

Commit

Permalink
[UI] Adding TTTableSection
Browse files Browse the repository at this point in the history
  • Loading branch information
Adar Porat committed Sep 26, 2011
1 parent 7c3de70 commit e241593
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 7 deletions.
8 changes: 4 additions & 4 deletions samples/TTCatalog/Classes/TableItemTestController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self.title = @"Table Items";
self.variableHeightRows = YES;

// Uncomment this to see how the table looks with the grouped style
//self.tableViewStyle = UITableViewStyleGrouped;
// comment this to see how the table looks with the standard style
self.tableViewStyle = UITableViewStyleGrouped;

// Uncomment this to see how the table cells look against a custom background color
//self.tableView.backgroundColor = [UIColor yellowColor];
Expand All @@ -37,9 +37,9 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
@"Generic Items",
[TTTableSettingsItem itemWithText:Three20Version caption:@"Three20 Version"
URL:@"tt://tableItemTest"],
@"Links and Buttons",
[TTTableTextItem itemWithText:@"TTTableTextItem" URL:@"tt://tableItemTest"
accessoryURL:@"http://www.google.com"],
[TTTableSection sectionWithHeaderTitle:@"Links & Buttons" footerTitle:nil],
[TTTableLink itemWithText:@"TTTableLink" URL:@"tt://tableItemTest"],
[TTTableButton itemWithText:@"TTTableButton"],
[TTTableCaptionItem itemWithText:@"TTTableCaptionItem" caption:@"caption"
Expand All @@ -50,7 +50,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
text:kLoremIpsum timestamp:[NSDate date] URL:@"tt://tableItemTest"],
[TTTableMoreButton itemWithText:@"TTTableMoreButton"],

@"Images",
[TTTableSection sectionWithHeaderTitle:@"Images" footerTitle:@"Usage of images inside TTTableView"],
[TTTableImageItem itemWithText:@"TTTableImageItem" imageURL:localImage
URL:@"tt://tableItemTest"],
[TTTableRightImageItem itemWithText:@"TTTableRightImageItem" imageURL:localImage
Expand Down
31 changes: 31 additions & 0 deletions src/Three20UI/Headers/TTTableSection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <UIKit/UIKit.h>


@interface TTTableSection : NSObject {
NSString* _headerTitle;
NSString* _footerTitle;
}

@property (nonatomic, copy) NSString* headerTitle;
@property (nonatomic, copy) NSString* footerTitle;


+ (id)sectionWithHeaderTitle:(NSString*)headerTitle footerTitle:(NSString*)footerTitle;

@end
1 change: 1 addition & 0 deletions src/Three20UI/Headers/Three20UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
#import "Three20UI/TTListDataSource.h"
#import "Three20UI/TTSectionedDataSource.h"
#import "Three20UI/TTTableHeaderView.h"
#import "Three20UI/TTTableSection.h"
#import "Three20UI/TTTableFooterInfiniteScrollView.h"
#import "Three20UI/TTTableHeaderDragRefreshView.h"
#import "Three20UI/TTTableViewCell.h"
Expand Down
28 changes: 25 additions & 3 deletions src/Three20UI/Sources/TTSectionedDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

// UI
#import "Three20UI/TTTableItem.h"
#import "Three20UI/TTTableSection.h"

// Core
#import "Three20Core/TTCorePreprocessorMacros.h"
Expand Down Expand Up @@ -67,7 +68,8 @@ + (TTSectionedDataSource*)dataSourceWithObjects:(id)object,... {
va_list ap;
va_start(ap, object);
while (object) {
if ([object isKindOfClass:[NSString class]]) {
if ([object isKindOfClass:[NSString class]] ||
[object isKindOfClass:[TTTableSection class]]) {
[sections addObject:object];
section = [NSMutableArray array];
[items addObject:section];
Expand All @@ -90,7 +92,8 @@ + (TTSectionedDataSource*)dataSourceWithArrays:(id)object,... {
va_list ap;
va_start(ap, object);
while (object) {
if ([object isKindOfClass:[NSString class]]) {
if ([object isKindOfClass:[NSString class]] ||
[object isKindOfClass:[TTTableSection class]]) {
[sections addObject:object];

} else {
Expand Down Expand Up @@ -137,7 +140,26 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
///////////////////////////////////////////////////////////////////////////////////////////////////
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (_sections.count) {
return [_sections objectAtIndex:section];
if ([[_sections objectAtIndex:section] isKindOfClass:[TTTableSection class]]) {
TTTableSection* sectionInfo = [_sections objectAtIndex:section];
return sectionInfo.headerTitle;

} else {
return [_sections objectAtIndex:section];
}

} else {
return nil;
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
if (tableView.style==UITableViewStyleGrouped &&
_sections.count &&
[[_sections objectAtIndex:section] isKindOfClass:[TTTableSection class]]) {
TTTableSection* sectionInfo = [_sections objectAtIndex:section];
return sectionInfo.footerTitle;

} else {
return nil;
Expand Down
51 changes: 51 additions & 0 deletions src/Three20UI/Sources/TTTableSection.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "Three20UI/TTTableSection.h"

// Core
#import "Three20Core/TTCorePreprocessorMacros.h"


///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation TTTableSection

@synthesize headerTitle = _headerTitle;
@synthesize footerTitle = _footerTitle;


///////////////////////////////////////////////////////////////////////////////////////////////////
+ (id)sectionWithHeaderTitle:(NSString*)headerTitle footerTitle:(NSString*)footerTitle {
TTTableSection* item = [[[self alloc] init] autorelease];
item.headerTitle = headerTitle;
item.footerTitle = footerTitle;
return item;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc {
TT_RELEASE_SAFELY(_headerTitle);
TT_RELEASE_SAFELY(_footerTitle);

[super dealloc];
}


@end

16 changes: 16 additions & 0 deletions src/Three20UI/Three20UI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
66F2E85712D426AF006FB485 /* TTTableFooterInfiniteScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 66F2E85512D426AF006FB485 /* TTTableFooterInfiniteScrollView.m */; };
66F2E85F12D426DA006FB485 /* TTTableViewNetworkEnabledDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 66F2E85D12D426DA006FB485 /* TTTableViewNetworkEnabledDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
66F2E86512D426EF006FB485 /* TTTableViewNetworkEnabledDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 66F2E86312D426EF006FB485 /* TTTableViewNetworkEnabledDelegate.m */; };
6D31FEDB14312683006C6B7F /* TTTableSection.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D31FEDA14312683006C6B7F /* TTTableSection.h */; settings = {ATTRIBUTES = (Public, ); }; };
6D31FEDD1431268C006C6B7F /* TTTableSection.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D31FEDC1431268C006C6B7F /* TTTableSection.m */; };
6DB1E37D13CA885B00A72466 /* TTLauncherPersistenceMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 6DB1E37C13CA885B00A72466 /* TTLauncherPersistenceMode.h */; settings = {ATTRIBUTES = (Public, ); }; };
6DD20D35141D0C1B00916A4A /* TTTableSettingsItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 6DD20D34141D0C1B00916A4A /* TTTableSettingsItem.h */; settings = {ATTRIBUTES = (Public, ); }; };
6DD20D37141D0C2800916A4A /* TTTableSettingsItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 6DD20D36141D0C2800916A4A /* TTTableSettingsItem.m */; };
Expand Down Expand Up @@ -448,6 +450,8 @@
66F2E85512D426AF006FB485 /* TTTableFooterInfiniteScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TTTableFooterInfiniteScrollView.m; path = Sources/TTTableFooterInfiniteScrollView.m; sourceTree = "<group>"; };
66F2E85D12D426DA006FB485 /* TTTableViewNetworkEnabledDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TTTableViewNetworkEnabledDelegate.h; path = Headers/TTTableViewNetworkEnabledDelegate.h; sourceTree = "<group>"; };
66F2E86312D426EF006FB485 /* TTTableViewNetworkEnabledDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TTTableViewNetworkEnabledDelegate.m; path = Sources/TTTableViewNetworkEnabledDelegate.m; sourceTree = "<group>"; };
6D31FEDA14312683006C6B7F /* TTTableSection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TTTableSection.h; path = Headers/TTTableSection.h; sourceTree = "<group>"; };
6D31FEDC1431268C006C6B7F /* TTTableSection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TTTableSection.m; path = Sources/TTTableSection.m; sourceTree = "<group>"; };
6DB1E37C13CA885B00A72466 /* TTLauncherPersistenceMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TTLauncherPersistenceMode.h; path = Headers/TTLauncherPersistenceMode.h; sourceTree = "<group>"; };
6DD20D34141D0C1B00916A4A /* TTTableSettingsItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TTTableSettingsItem.h; path = Headers/TTTableSettingsItem.h; sourceTree = "<group>"; };
6DD20D36141D0C2800916A4A /* TTTableSettingsItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TTTableSettingsItem.m; path = Sources/TTTableSettingsItem.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -783,6 +787,15 @@
name = Extensions;
sourceTree = "<group>";
};
6D31FED61431266E006C6B7F /* Table Section */ = {
isa = PBXGroup;
children = (
6D31FEDA14312683006C6B7F /* TTTableSection.h */,
6D31FEDC1431268C006C6B7F /* TTTableSection.m */,
);
name = "Table Section";
sourceTree = "<group>";
};
6E08B274118282F700DA1579 /* Tests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1294,6 +1307,7 @@
6E6458271184DF1E00F08CB1 /* Tables */ = {
isa = PBXGroup;
children = (
6D31FED61431266E006C6B7F /* Table Section */,
6E6458281184DF5F00F08CB1 /* Table Controller */,
6E6458291184DF6C00F08CB1 /* Table Delegate */,
6E64582C1184DFC500F08CB1 /* Table Data Source */,
Expand Down Expand Up @@ -1877,6 +1891,7 @@
6DB1E37D13CA885B00A72466 /* TTLauncherPersistenceMode.h in Headers */,
6DD20D35141D0C1B00916A4A /* TTTableSettingsItem.h in Headers */,
6DD20D3B141D0C4800916A4A /* TTTableSettingsItemCell.h in Headers */,
6D31FEDB14312683006C6B7F /* TTTableSection.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -2239,6 +2254,7 @@
66F2E86512D426EF006FB485 /* TTTableViewNetworkEnabledDelegate.m in Sources */,
6DD20D37141D0C2800916A4A /* TTTableSettingsItem.m in Sources */,
6DD20D39141D0C3A00916A4A /* TTTableSettingsItemCell.m in Sources */,
6D31FEDD1431268C006C6B7F /* TTTableSection.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit e241593

Please sign in to comment.