|
| 1 | +// |
| 2 | +// DetailViewController.m |
| 3 | +// Lisp |
| 4 | +// |
| 5 | +// Created by David Pollak on 6/7/11. |
| 6 | +// Copyright 2011 lift Web Framework. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "DetailViewController.h" |
| 10 | +#import "RootViewController.h" |
| 11 | + |
| 12 | +static void (*cb_viewDidLoad)(void*); |
| 13 | + |
| 14 | +void setViewDidLoad(void (*fp)(void*)) |
| 15 | +{ |
| 16 | + cb_viewDidLoad = fp; |
| 17 | +} |
| 18 | + |
| 19 | +void addToResult(DetailViewController* vc, char *str) |
| 20 | +{ |
| 21 | + NSString *resStr = [[NSString alloc] initWithCString:str]; |
| 22 | + |
| 23 | + NSString *curText = vc.tableDude.text; |
| 24 | + vc.tableDude.text = [[curText stringByAppendingString:@": "] stringByAppendingString:resStr]; |
| 25 | +} |
| 26 | + |
| 27 | +void setLispEval(DetailViewController *vc, void (*cb)(void *vc, const char *)) |
| 28 | +{ |
| 29 | + vc -> cb_lispEval = cb; |
| 30 | +} |
| 31 | + |
| 32 | +@interface DetailViewController () |
| 33 | +@property (nonatomic, retain) UIPopoverController *popoverController; |
| 34 | +- (void)configureView; |
| 35 | +@end |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +@implementation DetailViewController |
| 40 | + |
| 41 | +@synthesize toolbar, popoverController, detailItem, detailDescriptionLabel, textField, tableDude; |
| 42 | + |
| 43 | + |
| 44 | +-(IBAction)buttonPressed: (id)sender { |
| 45 | + NSString *curVal = textField.text; |
| 46 | + [curVal retain]; |
| 47 | + |
| 48 | + NSString *curText = tableDude.text; |
| 49 | + tableDude.text = [[curText stringByAppendingString:@"\n"] stringByAppendingString:curVal]; |
| 50 | + |
| 51 | + textField.text = [[NSString alloc] init]; |
| 52 | + const char *str = [curVal UTF8String]; |
| 53 | + |
| 54 | + (*cb_lispEval)(self, str); |
| 55 | + [curVal release]; |
| 56 | +} |
| 57 | + |
| 58 | +#pragma mark - |
| 59 | +#pragma mark Managing the detail item |
| 60 | + |
| 61 | +/* |
| 62 | + When setting the detail item, update the view and dismiss the popover controller if it's showing. |
| 63 | + */ |
| 64 | +- (void)setDetailItem:(id)newDetailItem { |
| 65 | + if (detailItem != newDetailItem) { |
| 66 | + [detailItem release]; |
| 67 | + detailItem = [newDetailItem retain]; |
| 68 | + |
| 69 | + // Update the view. |
| 70 | + [self configureView]; |
| 71 | + } |
| 72 | + |
| 73 | + if (self.popoverController != nil) { |
| 74 | + [self.popoverController dismissPopoverAnimated:YES]; |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | + |
| 79 | +- (void)configureView { |
| 80 | + // Update the user interface for the detail item. |
| 81 | + detailDescriptionLabel.text = [detailItem description]; |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | +#pragma mark - |
| 86 | +#pragma mark Split view support |
| 87 | + |
| 88 | +- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc { |
| 89 | + |
| 90 | + barButtonItem.title = @"Root List"; |
| 91 | + NSMutableArray *items = [[toolbar items] mutableCopy]; |
| 92 | + [items insertObject:barButtonItem atIndex:0]; |
| 93 | + [toolbar setItems:items animated:YES]; |
| 94 | + [items release]; |
| 95 | + self.popoverController = pc; |
| 96 | +} |
| 97 | + |
| 98 | + |
| 99 | +// Called when the view is shown again in the split view, invalidating the button and popover controller. |
| 100 | +- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem { |
| 101 | + |
| 102 | + NSMutableArray *items = [[toolbar items] mutableCopy]; |
| 103 | + [items removeObjectAtIndex:0]; |
| 104 | + [toolbar setItems:items animated:YES]; |
| 105 | + [items release]; |
| 106 | + self.popoverController = nil; |
| 107 | +} |
| 108 | + |
| 109 | + |
| 110 | +#pragma mark - |
| 111 | +#pragma mark Rotation support |
| 112 | + |
| 113 | +// Ensure that the view controller supports rotation and that the split view can therefore show in both portrait and landscape. |
| 114 | +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
| 115 | + return YES; |
| 116 | +} |
| 117 | + |
| 118 | + |
| 119 | +#pragma mark - |
| 120 | +#pragma mark View lifecycle |
| 121 | + |
| 122 | +// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. |
| 123 | +- (void)viewDidLoad { |
| 124 | + [super viewDidLoad]; |
| 125 | + self -> cb_lispEval = NULL; |
| 126 | + cb_viewDidLoad(self); |
| 127 | +} |
| 128 | + |
| 129 | +/* |
| 130 | +
|
| 131 | + */ |
| 132 | + |
| 133 | +/* |
| 134 | +- (void)viewWillAppear:(BOOL)animated { |
| 135 | + [super viewWillAppear:animated]; |
| 136 | +} |
| 137 | +*/ |
| 138 | +/* |
| 139 | +- (void)viewDidAppear:(BOOL)animated { |
| 140 | + [super viewDidAppear:animated]; |
| 141 | +} |
| 142 | +*/ |
| 143 | +/* |
| 144 | +- (void)viewWillDisappear:(BOOL)animated { |
| 145 | + [super viewWillDisappear:animated]; |
| 146 | +} |
| 147 | +*/ |
| 148 | +/* |
| 149 | +- (void)viewDidDisappear:(BOOL)animated { |
| 150 | + [super viewDidDisappear:animated]; |
| 151 | +} |
| 152 | +*/ |
| 153 | + |
| 154 | +- (void)viewDidUnload { |
| 155 | + // Release any retained subviews of the main view. |
| 156 | + // e.g. self.myOutlet = nil; |
| 157 | + self.popoverController = nil; |
| 158 | +} |
| 159 | + |
| 160 | + |
| 161 | +#pragma mark - |
| 162 | +#pragma mark Memory management |
| 163 | + |
| 164 | +/* |
| 165 | +- (void)didReceiveMemoryWarning { |
| 166 | + // Releases the view if it doesn't have a superview. |
| 167 | + [super didReceiveMemoryWarning]; |
| 168 | + |
| 169 | + // Release any cached data, images, etc that aren't in use. |
| 170 | +} |
| 171 | +*/ |
| 172 | + |
| 173 | +- (void)dealloc { |
| 174 | + [popoverController release]; |
| 175 | + [toolbar release]; |
| 176 | + |
| 177 | + [detailItem release]; |
| 178 | + [detailDescriptionLabel release]; |
| 179 | + [super dealloc]; |
| 180 | +} |
| 181 | + |
| 182 | +@end |
0 commit comments