Skip to content

Commit

Permalink
Right view controller in demo now logs delegate methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Inferis committed Dec 21, 2011
1 parent b3025a5 commit a28a3f9
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 39 deletions.
5 changes: 3 additions & 2 deletions ViewDeckExample/RightViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

#import <UIKit/UIKit.h>

@interface RightViewController : UIViewController
@interface RightViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) IBOutlet UITableView* tableView;

- (IBAction)defaultCenterPressed:(id)sender;
- (IBAction)swapLeftAndCenterPressed:(id)sender;
- (IBAction)imageAsCenterPressed:(id)sender;

@end
101 changes: 100 additions & 1 deletion ViewDeckExample/RightViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
#import "ViewController.h"
#import "IIViewDeckController.h"

@interface RightViewController () <IIViewDeckControllerDelegate>

@property (nonatomic, retain) NSMutableArray* logs;

@end


@implementation RightViewController

@synthesize tableView = _tableView;
@synthesize logs = _logs;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
Expand All @@ -28,6 +38,14 @@ - (void)didReceiveMemoryWarning
// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidLoad {
[super viewDidLoad];

self.logs = [NSMutableArray array];

self.viewDeckController.delegate = self;
}

#pragma mark - View lifecycle

- (IBAction)defaultCenterPressed:(id)sender {
Expand All @@ -40,7 +58,88 @@ - (IBAction)swapLeftAndCenterPressed:(id)sender {
self.viewDeckController.leftController = SharedAppDelegate.centerController;
}

- (IBAction)imageAsCenterPressed:(id)sender {
#pragma mark - view deck delegate

- (void)addLog:(NSString*)line {
self.tableView.frame = (CGRect) { self.viewDeckController.rightLedge, self.tableView.frame.origin.y,
self.view.frame.size.width - self.viewDeckController.rightLedge, self.tableView.frame.size.height };

[self.logs addObject:line];
NSIndexPath* index = [NSIndexPath indexPathForRow:self.logs.count-1 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationBottom];
[self.tableView scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}

- (void)viewDeckController:(IIViewDeckController*)viewDeckController didPanToOffset:(CGFloat)offset {
[self addLog:[NSString stringWithFormat:@"Pan: %f", offset]];
}

- (BOOL)viewDeckControllerWillOpenLeftView:(IIViewDeckController*)viewDeckController animated:(BOOL)animated {
[self addLog:@"will open left view"];
return YES;
}

- (void)viewDeckControllerDidOpenLeftView:(IIViewDeckController*)viewDeckController animated:(BOOL)animated {
[self addLog:@"did open left view"];
}

- (BOOL)viewDeckControllerWillCloseLeftView:(IIViewDeckController*)viewDeckController animated:(BOOL)animated {
[self addLog:@"will close left view"];
return YES;
}

- (void)viewDeckControllerDidCloseLeftView:(IIViewDeckController*)viewDeckController animated:(BOOL)animated {
[self addLog:@"did close left view"];
}

- (BOOL)viewDeckControllerWillOpenRightView:(IIViewDeckController*)viewDeckController animated:(BOOL)animated {
[self addLog:@"will open right view"];
return YES;
}

- (void)viewDeckControllerDidOpenRightView:(IIViewDeckController*)viewDeckController animated:(BOOL)animated {
[self addLog:@"did open right view"];
}

- (BOOL)viewDeckControllerWillCloseRightView:(IIViewDeckController*)viewDeckController animated:(BOOL)animated {
[self addLog:@"will close left view"];
return YES;
}

- (void)viewDeckControllerDidCloseRightView:(IIViewDeckController*)viewDeckController animated:(BOOL)animated {
[self addLog:@"did close left view"];
}

- (void)viewDeckControllerDidShowCenterView:(IIViewDeckController*)viewDeckController animated:(BOOL)animated {
[self addLog:@"did show center view"];
}

#pragma mark - Table view

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.logs.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = [UIFont boldSystemFontOfSize:13];
cell.textLabel.text = [self.logs objectAtIndex:indexPath.row];

return cell;
}


Expand Down
90 changes: 54 additions & 36 deletions ViewDeckExample/RightViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<string>IBUIButton</string>
<string>IBUIImageView</string>
<string>IBUIView</string>
<string>IBUITableView</string>
<string>IBProxyObject</string>
</array>
<array key="IBDocument.PluginDependencies">
Expand Down Expand Up @@ -54,7 +55,7 @@
<object class="IBUIButton" id="691437836">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{127, 20}, {173, 92}}</string>
<string key="NSFrame">{{127, 20}, {173, 51}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="827011900"/>
Expand Down Expand Up @@ -90,10 +91,10 @@
<object class="IBUIButton" id="827011900">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{127, 120}, {173, 92}}</string>
<string key="NSFrame">{{127, 79}, {173, 51}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="875385754"/>
<reference key="NSNextKeyView" ref="752954144"/>
<string key="NSReuseIdentifierKey">_NS:225</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
Expand All @@ -110,28 +111,24 @@
<reference key="IBUIFontDescription" ref="1033390871"/>
<reference key="IBUIFont" ref="833115814"/>
</object>
<object class="IBUIButton" id="875385754">
<object class="IBUITableView" id="752954144">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{127, 220}, {173, 92}}</string>
<int key="NSvFlags">274</int>
<string key="NSFrame">{{0, 153}, {320, 307}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:225</string>
<bool key="IBUIOpaque">NO</bool>
<string key="NSReuseIdentifierKey">_NS:418</string>
<reference key="IBUIBackgroundColor" ref="496081773"/>
<bool key="IBUIClipsSubviews">YES</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">Image Center</string>
<reference key="IBUIHighlightedTitleColor" ref="496081773"/>
<object class="NSColor" key="IBUINormalTitleColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA</bytes>
</object>
<reference key="IBUINormalTitleShadowColor" ref="49500627"/>
<reference key="IBUIFontDescription" ref="1033390871"/>
<reference key="IBUIFont" ref="833115814"/>
<bool key="IBUIAlwaysBounceVertical">YES</bool>
<int key="IBUISeparatorStyle">1</int>
<int key="IBUISectionIndexMinimumDisplayRowCount">0</int>
<bool key="IBUIShowsSelectionImmediatelyOnTouchBegin">YES</bool>
<float key="IBUIRowHeight">28</float>
<float key="IBUISectionHeaderHeight">22</float>
<float key="IBUISectionFooterHeight">22</float>
</object>
</array>
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
Expand All @@ -156,6 +153,14 @@
</object>
<int key="connectionID">3</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">tableView</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="752954144"/>
</object>
<int key="connectionID">16</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">defaultCenterPressed:</string>
Expand All @@ -175,13 +180,20 @@
<int key="connectionID">9</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">imageAsCenterPressed:</string>
<reference key="source" ref="875385754"/>
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">dataSource</string>
<reference key="source" ref="752954144"/>
<reference key="destination" ref="372490531"/>
<int key="IBEventType">7</int>
</object>
<int key="connectionID">10</int>
<int key="connectionID">14</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="752954144"/>
<reference key="destination" ref="372490531"/>
</object>
<int key="connectionID">15</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
Expand All @@ -196,10 +208,10 @@
<int key="objectID">1</int>
<reference key="object" ref="191373211"/>
<array class="NSMutableArray" key="children">
<reference ref="765695467"/>
<reference ref="691437836"/>
<reference ref="752954144"/>
<reference ref="827011900"/>
<reference ref="875385754"/>
<reference ref="765695467"/>
</array>
<reference key="parent" ref="0"/>
</object>
Expand Down Expand Up @@ -230,8 +242,8 @@
<reference key="parent" ref="191373211"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">7</int>
<reference key="object" ref="875385754"/>
<int key="objectID">13</int>
<reference key="object" ref="752954144"/>
<reference key="parent" ref="191373211"/>
</object>
</array>
Expand All @@ -242,16 +254,16 @@
<string key="-2.CustomClassName">UIResponder</string>
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="13.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="4.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="5.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="7.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">10</int>
<int key="maxID">16</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand All @@ -260,23 +272,29 @@
<string key="superclassName">UIViewController</string>
<dictionary class="NSMutableDictionary" key="actions">
<string key="defaultCenterPressed:">id</string>
<string key="imageAsCenterPressed:">id</string>
<string key="swapLeftAndCenterPressed:">id</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="actionInfosByName">
<object class="IBActionInfo" key="defaultCenterPressed:">
<string key="name">defaultCenterPressed:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="imageAsCenterPressed:">
<string key="name">imageAsCenterPressed:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="swapLeftAndCenterPressed:">
<string key="name">swapLeftAndCenterPressed:</string>
<string key="candidateClassName">id</string>
</object>
</dictionary>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">tableView</string>
<string key="NS.object.0">UITableView</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<string key="NS.key.0">tableView</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
<string key="name">tableView</string>
<string key="candidateClassName">UITableView</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/RightViewController.h</string>
Expand Down

0 comments on commit a28a3f9

Please sign in to comment.