|
| 1 | +// |
| 2 | +// RootViewController.m |
| 3 | +// UIDeviceSample |
| 4 | +// |
| 5 | +// Created by Hiroshi Hashiguchi on 10/09/12. |
| 6 | +// Copyright Hiroshi Hashiguchi 2010. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "RootViewController.h" |
| 10 | + |
| 11 | + |
| 12 | +@implementation RootViewController |
| 13 | + |
| 14 | + |
| 15 | +#pragma mark - |
| 16 | +#pragma mark View lifecycle |
| 17 | + |
| 18 | +- (void)viewDidLoad { |
| 19 | + [super viewDidLoad]; |
| 20 | + self.title = @"UIDevice Properties"; |
| 21 | + |
| 22 | + UIDevice* device = [UIDevice currentDevice]; |
| 23 | + device.batteryMonitoringEnabled = YES; |
| 24 | + |
| 25 | + tasks = [[NSArray alloc] initWithObjects: |
| 26 | + @"Determining the Available Features", |
| 27 | + @"Identifying the Device and Operating System", |
| 28 | + @"Getting the Device Orientation", |
| 29 | + @"Getting the Device Battery State", |
| 30 | + @"Using the Proximity Sensor", |
| 31 | + nil |
| 32 | + ]; |
| 33 | + |
| 34 | + properties = [[NSArray alloc] initWithObjects: |
| 35 | + [NSArray arrayWithObjects: |
| 36 | + @"multitaskingSupported", |
| 37 | + nil], |
| 38 | + |
| 39 | + [NSArray arrayWithObjects: |
| 40 | + @"uniqueIdentifier", |
| 41 | + @"name", |
| 42 | + @"systemName", |
| 43 | + @"systemVersion", |
| 44 | + @"model", |
| 45 | + @"localizedModel", |
| 46 | + @"userInterfaceIdiom", |
| 47 | + nil], |
| 48 | + |
| 49 | + [NSArray arrayWithObjects: |
| 50 | + @"orientation", |
| 51 | + @"isGeneratingDeviceOrientationNotifications", |
| 52 | + nil], |
| 53 | + |
| 54 | + [NSArray arrayWithObjects: |
| 55 | + @"batteryLevel", |
| 56 | + @"batteryMonitoringEnabled", |
| 57 | + @"batteryState", |
| 58 | + nil], |
| 59 | + |
| 60 | + [NSArray arrayWithObjects: |
| 61 | + @"proximityMonitoringEnabled", |
| 62 | + @"proximityState", |
| 63 | + nil], |
| 64 | + |
| 65 | + nil]; |
| 66 | + |
| 67 | +} |
| 68 | + |
| 69 | +/* |
| 70 | +- (void)viewWillAppear:(BOOL)animated { |
| 71 | + [super viewWillAppear:animated]; |
| 72 | +} |
| 73 | +*/ |
| 74 | +/* |
| 75 | +- (void)viewDidAppear:(BOOL)animated { |
| 76 | + [super viewDidAppear:animated]; |
| 77 | +} |
| 78 | +*/ |
| 79 | +/* |
| 80 | +- (void)viewWillDisappear:(BOOL)animated { |
| 81 | + [super viewWillDisappear:animated]; |
| 82 | +} |
| 83 | +*/ |
| 84 | +/* |
| 85 | +- (void)viewDidDisappear:(BOOL)animated { |
| 86 | + [super viewDidDisappear:animated]; |
| 87 | +} |
| 88 | +*/ |
| 89 | + |
| 90 | +/* |
| 91 | + // Override to allow orientations other than the default portrait orientation. |
| 92 | +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
| 93 | + // Return YES for supported orientations. |
| 94 | + return (interfaceOrientation == UIInterfaceOrientationPortrait); |
| 95 | +} |
| 96 | + */ |
| 97 | + |
| 98 | + |
| 99 | +#pragma mark - |
| 100 | +#pragma mark Table view data source |
| 101 | + |
| 102 | +// Customize the number of sections in the table view. |
| 103 | +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
| 104 | + return [tasks count]; |
| 105 | +} |
| 106 | + |
| 107 | + |
| 108 | +// Customize the number of rows in the table view. |
| 109 | +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
| 110 | + return [[properties objectAtIndex:section] count]; |
| 111 | +} |
| 112 | + |
| 113 | + |
| 114 | +// Customize the appearance of table view cells. |
| 115 | +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
| 116 | + |
| 117 | + static NSString *CellIdentifier = @"Cell"; |
| 118 | + |
| 119 | + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
| 120 | + if (cell == nil) { |
| 121 | + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; |
| 122 | + cell.textLabel.adjustsFontSizeToFitWidth = YES; |
| 123 | + CGRect rect = cell.frame; |
| 124 | + cell.frame = rect; |
| 125 | + } |
| 126 | + |
| 127 | + NSArray* props = [properties objectAtIndex:indexPath.section]; |
| 128 | + NSString* key = [props objectAtIndex:indexPath.row]; |
| 129 | + id value = [[UIDevice currentDevice] valueForKey:key]; |
| 130 | + |
| 131 | + cell.textLabel.text = key; |
| 132 | + cell.detailTextLabel.text = [value description]; |
| 133 | + |
| 134 | + return cell; |
| 135 | +} |
| 136 | + |
| 137 | + |
| 138 | +/* |
| 139 | +// Override to support conditional editing of the table view. |
| 140 | +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { |
| 141 | + // Return NO if you do not want the specified item to be editable. |
| 142 | + return YES; |
| 143 | +} |
| 144 | +*/ |
| 145 | + |
| 146 | + |
| 147 | +/* |
| 148 | +// Override to support editing the table view. |
| 149 | +- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
| 150 | + |
| 151 | + if (editingStyle == UITableViewCellEditingStyleDelete) { |
| 152 | + // Delete the row from the data source. |
| 153 | + [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; |
| 154 | + } |
| 155 | + else if (editingStyle == UITableViewCellEditingStyleInsert) { |
| 156 | + // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. |
| 157 | + } |
| 158 | +} |
| 159 | +*/ |
| 160 | + |
| 161 | + |
| 162 | +/* |
| 163 | +// Override to support rearranging the table view. |
| 164 | +- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { |
| 165 | +} |
| 166 | +*/ |
| 167 | + |
| 168 | + |
| 169 | +/* |
| 170 | +// Override to support conditional rearranging of the table view. |
| 171 | +- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { |
| 172 | + // Return NO if you do not want the item to be re-orderable. |
| 173 | + return YES; |
| 174 | +} |
| 175 | +*/ |
| 176 | + |
| 177 | + |
| 178 | +#pragma mark - |
| 179 | +#pragma mark Table view delegate |
| 180 | + |
| 181 | +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
| 182 | + |
| 183 | + /* |
| 184 | + <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; |
| 185 | + // ... |
| 186 | + // Pass the selected object to the new view controller. |
| 187 | + [self.navigationController pushViewController:detailViewController animated:YES]; |
| 188 | + [detailViewController release]; |
| 189 | + */ |
| 190 | +} |
| 191 | + |
| 192 | + |
| 193 | +#pragma mark - |
| 194 | +#pragma mark Memory management |
| 195 | + |
| 196 | +- (void)didReceiveMemoryWarning { |
| 197 | + // Releases the view if it doesn't have a superview. |
| 198 | + [super didReceiveMemoryWarning]; |
| 199 | + |
| 200 | + // Relinquish ownership any cached data, images, etc that aren't in use. |
| 201 | +} |
| 202 | + |
| 203 | +- (void)viewDidUnload { |
| 204 | + // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. |
| 205 | + // For example: self.myOutlet = nil; |
| 206 | +} |
| 207 | + |
| 208 | + |
| 209 | +- (void)dealloc { |
| 210 | + [super dealloc]; |
| 211 | +} |
| 212 | + |
| 213 | +- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section |
| 214 | +{ |
| 215 | + return [tasks objectAtIndex:section]; |
| 216 | +} |
| 217 | + |
| 218 | +@end |
| 219 | + |
0 commit comments