Skip to content

Commit a2c2312

Browse files
committed
Added tableviews example.
1 parent 50b75c9 commit a2c2312

13 files changed

+875
-0
lines changed

TableViewsExample/TableViewsExample.xcodeproj/project.pbxproj

+342
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// AppDelegate.h
3+
// TableViewsExample
4+
//
5+
// Created by Tom Adriaenssen on 16/05/13.
6+
// Copyright (c) 2013 Tom Adriaenssen. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@class ViewController;
12+
13+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
14+
15+
@property (strong, nonatomic) UIWindow *window;
16+
17+
@property (strong, nonatomic) ViewController *viewController;
18+
19+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// AppDelegate.m
3+
// TableViewsExample
4+
//
5+
// Created by Tom Adriaenssen on 16/05/13.
6+
// Copyright (c) 2013 Tom Adriaenssen. All rights reserved.
7+
//
8+
9+
#import "AppDelegate.h"
10+
11+
#import "ViewController.h"
12+
#import "IIViewDeckController.h"
13+
#import "IISideController.h"
14+
15+
@implementation AppDelegate
16+
17+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
18+
{
19+
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
20+
21+
ViewController* centerController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
22+
centerController.searchable = NO;
23+
ViewController* leftController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
24+
leftController.tintColor = [UIColor blackColor];
25+
ViewController* rightController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
26+
rightController.tintColor = [UIColor purpleColor];
27+
28+
IIViewDeckController* deckController = [[IIViewDeckController alloc] initWithCenterViewController:[[UINavigationController alloc] initWithRootViewController:centerController]
29+
leftViewController:[IISideController autoConstrainedSideControllerWithViewController:leftController]
30+
rightViewController:[IISideController autoConstrainedSideControllerWithViewController:rightController]];
31+
32+
self.window.rootViewController = deckController;
33+
34+
[self.window makeKeyAndVisible];
35+
return YES;
36+
}
37+
38+
- (void)applicationWillResignActive:(UIApplication *)application
39+
{
40+
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
41+
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
42+
}
43+
44+
- (void)applicationDidEnterBackground:(UIApplication *)application
45+
{
46+
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
47+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
48+
}
49+
50+
- (void)applicationWillEnterForeground:(UIApplication *)application
51+
{
52+
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
53+
}
54+
55+
- (void)applicationDidBecomeActive:(UIApplication *)application
56+
{
57+
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
58+
}
59+
60+
- (void)applicationWillTerminate:(UIApplication *)application
61+
{
62+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
63+
}
64+
65+
@end
Loading
6.39 KB
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleDisplayName</key>
8+
<string>${PRODUCT_NAME}</string>
9+
<key>CFBundleExecutable</key>
10+
<string>${EXECUTABLE_NAME}</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>org.inferis.${PRODUCT_NAME:rfc1034identifier}</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>${PRODUCT_NAME}</string>
17+
<key>CFBundlePackageType</key>
18+
<string>APPL</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleSignature</key>
22+
<string>????</string>
23+
<key>CFBundleVersion</key>
24+
<string>1.0</string>
25+
<key>LSRequiresIPhoneOS</key>
26+
<true/>
27+
<key>UIRequiredDeviceCapabilities</key>
28+
<array>
29+
<string>armv7</string>
30+
</array>
31+
<key>UISupportedInterfaceOrientations</key>
32+
<array>
33+
<string>UIInterfaceOrientationPortrait</string>
34+
<string>UIInterfaceOrientationLandscapeLeft</string>
35+
<string>UIInterfaceOrientationLandscapeRight</string>
36+
</array>
37+
</dict>
38+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Prefix header for all source files of the 'TableViewsExample' target in the 'TableViewsExample' project
3+
//
4+
5+
#import <Availability.h>
6+
7+
#ifndef __IPHONE_4_0
8+
#warning "This project uses features only available in iOS SDK 4.0 and later."
9+
#endif
10+
11+
#ifdef __OBJC__
12+
#import <UIKit/UIKit.h>
13+
#import <Foundation/Foundation.h>
14+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// ViewController.h
3+
// TableViewsExample
4+
//
5+
// Created by Tom Adriaenssen on 16/05/13.
6+
// Copyright (c) 2013 Tom Adriaenssen. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface ViewController : UITableViewController
12+
13+
@property (nonatomic, retain) UIColor* tintColor;
14+
@property (nonatomic, assign) BOOL searchable;
15+
16+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
//
2+
// ViewController.m
3+
// TableViewsExample
4+
//
5+
// Created by Tom Adriaenssen on 16/05/13.
6+
// Copyright (c) 2013 Tom Adriaenssen. All rights reserved.
7+
//
8+
9+
#import "ViewController.h"
10+
#import <objc/runtime.h>
11+
#import "IIViewDeckController.h"
12+
13+
@interface ViewController () <UISearchBarDelegate, UIGestureRecognizerDelegate>
14+
15+
@property (nonatomic, retain) IBOutlet UISearchBar* searchBar;
16+
17+
@end
18+
19+
@implementation ViewController {
20+
NSArray* _methods;
21+
NSArray* _allMethods;
22+
}
23+
24+
- (id)initWithStyle:(UITableViewStyle)style
25+
{
26+
self = [super initWithStyle:style];
27+
if (self) {
28+
// Custom initialization
29+
_searchable = YES;
30+
}
31+
return self;
32+
}
33+
34+
- (void)viewDidLoad
35+
{
36+
[super viewDidLoad];
37+
38+
uint count;
39+
Method* methodlist = class_copyMethodList([UITableView class], &count);
40+
41+
NSMutableArray* methods = [NSMutableArray new];
42+
for (int i=0; i<count; ++i) {
43+
NSString* name = NSStringFromSelector(method_getName(methodlist[i]));
44+
if ([name rangeOfString:@"_"].location != 0)
45+
[methods addObject:name];
46+
}
47+
48+
_allMethods = [methods sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES]]];
49+
[self filter:nil];
50+
51+
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(doEdit)];
52+
}
53+
54+
- (void)setTintColor:(UIColor *)tintColor {
55+
_tintColor = tintColor;
56+
57+
self.view; // fdj
58+
self.searchBar.tintColor = tintColor;
59+
}
60+
61+
- (void)setSearchable:(BOOL)searchable {
62+
_searchable = searchable;
63+
64+
self.view;
65+
if (searchable) {
66+
self.tableView.tableHeaderView = self.searchBar;
67+
}
68+
else {
69+
self.tableView.tableHeaderView = nil;
70+
}
71+
}
72+
73+
- (void)viewWillAppear:(BOOL)animated {
74+
[super viewWillAppear:animated];
75+
((UITableViewController*)self.viewDeckController.leftController).tableView.scrollsToTop = NO;
76+
UINavigationController* nc = self.viewDeckController.centerController;
77+
((UITableViewController*)nc.topViewController).tableView.scrollsToTop = NO;
78+
((UITableViewController*)self.viewDeckController.rightController).tableView.scrollsToTop = NO;
79+
self.tableView.scrollsToTop = YES;
80+
}
81+
82+
- (void)filter:(NSString*)filter {
83+
if (filter) {
84+
_methods = [_allMethods filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self beginswith[cd] %@", filter]];
85+
}
86+
else {
87+
_methods = _allMethods;
88+
}
89+
90+
[[self tableView] reloadData];
91+
}
92+
93+
#pragma mark - search
94+
95+
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
96+
[self filter:searchText];
97+
}
98+
99+
#pragma mark - Table view data source
100+
101+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
102+
{
103+
return _methods.count;
104+
}
105+
106+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
107+
{
108+
static NSString *CellIdentifier = @"Cell";
109+
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
110+
if (cell == nil) {
111+
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
112+
}
113+
114+
cell.textLabel.text = _methods[indexPath.row];
115+
cell.textLabel.adjustsFontSizeToFitWidth = YES;
116+
cell.showsReorderControl = YES;
117+
118+
return cell;
119+
}
120+
121+
122+
// Override to support rearranging the table view.
123+
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
124+
{
125+
}
126+
127+
128+
// Override to support conditional rearranging of the table view.
129+
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
130+
{
131+
// Return NO if you do not want the item to be re-orderable.
132+
return YES;
133+
}
134+
135+
136+
#pragma mark - Table view delegate
137+
138+
139+
- (void)doEdit {
140+
[self.tableView setEditing:!self.tableView.editing animated:YES];
141+
if (self.tableView.editing)
142+
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doEdit)];
143+
else
144+
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(doEdit)];
145+
}
146+
147+
@end

0 commit comments

Comments
 (0)