root / Classes / AddObjectViewController.m @ 9fee07a6
History | View | Annotate | Download (3.8 kB)
1 |
// |
---|---|
2 |
// AddObjectViewController.m |
3 |
// OpenStack |
4 |
// |
5 |
// Created by Mike Mayo on 1/4/11. |
6 |
// Copyright 2011 __MyCompanyName__. All rights reserved. |
7 |
// |
8 |
|
9 |
#import "AddObjectViewController.h" |
10 |
#import "UIViewController+Conveniences.h" |
11 |
#import "AddFolderViewController.h" |
12 |
#import "AddFileViewController.h" |
13 |
|
14 |
#define kFolder 0 |
15 |
#define kFile 1 |
16 |
|
17 |
@implementation AddObjectViewController |
18 |
|
19 |
@synthesize account, container, folder, folderViewController; |
20 |
|
21 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { |
22 |
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait); |
23 |
} |
24 |
|
25 |
#pragma mark - |
26 |
#pragma mark View lifecycle |
27 |
|
28 |
- (void)viewDidLoad { |
29 |
[super viewDidLoad]; |
30 |
self.navigationItem.title = @"Add Object"; |
31 |
[self addCancelButton]; |
32 |
} |
33 |
|
34 |
#pragma mark - |
35 |
#pragma mark Table view data source |
36 |
|
37 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
38 |
return 2; |
39 |
} |
40 |
|
41 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
42 |
return 1; |
43 |
} |
44 |
|
45 |
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { |
46 |
if (section == kFolder) { |
47 |
return @"A folder is represented as a zero byte directory marker object in this container."; |
48 |
} else if (section == kFile) { |
49 |
return [NSString stringWithFormat:@"Files can be added from your %@ or synced from iTunes.", [[UIDevice currentDevice] model]]; |
50 |
} else { |
51 |
return @""; |
52 |
} |
53 |
} |
54 |
|
55 |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
56 |
|
57 |
static NSString *CellIdentifier = @"Cell"; |
58 |
|
59 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
60 |
if (cell == nil) { |
61 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
62 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
63 |
} |
64 |
|
65 |
// Configure the cell... |
66 |
if (indexPath.section == kFolder) { |
67 |
cell.textLabel.text = @"Add a Folder"; |
68 |
cell.imageView.image = [UIImage imageNamed:@"folder-icon.png"]; |
69 |
} else if (indexPath.section == kFile) { |
70 |
cell.textLabel.text = @"Add a File"; |
71 |
NSString *emptyPath = [[NSBundle mainBundle] pathForResource:@"empty-file" ofType:@""]; |
72 |
UIDocumentInteractionController *udic = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:emptyPath]]; |
73 |
cell.imageView.image = [udic.icons objectAtIndex:0]; //[UIImage imageNamed:@"file-icon.png"]; |
74 |
} |
75 |
|
76 |
return cell; |
77 |
} |
78 |
|
79 |
#pragma mark - |
80 |
#pragma mark Table view delegate |
81 |
|
82 |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
83 |
if (indexPath.section == kFolder) { |
84 |
AddFolderViewController *vc = [[AddFolderViewController alloc] initWithNibName:@"AddFolderViewController" bundle:nil]; |
85 |
vc.account = self.account; |
86 |
vc.container = self.container; |
87 |
vc.folder = self.folder; |
88 |
vc.folderViewController = self.folderViewController; |
89 |
[self.navigationController pushViewController:vc animated:YES]; |
90 |
[vc release]; |
91 |
} else if (indexPath.section == kFile) { |
92 |
AddFileViewController *vc = [[AddFileViewController alloc] initWithNibName:@"AddFileViewController" bundle:nil]; |
93 |
vc.account = self.account; |
94 |
vc.container = self.container; |
95 |
vc.folder = self.folder; |
96 |
vc.folderViewController = self.folderViewController; |
97 |
[self.navigationController pushViewController:vc animated:YES]; |
98 |
[vc release]; |
99 |
} |
100 |
} |
101 |
|
102 |
#pragma mark - |
103 |
#pragma mark Memory management |
104 |
|
105 |
- (void)dealloc { |
106 |
[account release]; |
107 |
[container release]; |
108 |
[folder release]; |
109 |
[folderViewController release]; |
110 |
[super dealloc]; |
111 |
} |
112 |
|
113 |
@end |