2 // AddObjectViewController.m
5 // Created by Mike Mayo on 1/4/11.
6 // Copyright 2011 __MyCompanyName__. All rights reserved.
9 #import "AddObjectViewController.h"
10 #import "UIViewController+Conveniences.h"
11 #import "AddFolderViewController.h"
12 #import "AddFileViewController.h"
17 @implementation AddObjectViewController
19 @synthesize account, container, folder, folderViewController;
21 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
22 return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
26 #pragma mark View lifecycle
30 self.navigationItem.title = @"Add Object";
31 [self addCancelButton];
35 #pragma mark Table view data source
37 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
41 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
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]];
55 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
57 static NSString *CellIdentifier = @"Cell";
59 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
61 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
62 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
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"];
80 #pragma mark Table view delegate
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];
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];
103 #pragma mark Memory management
109 [folderViewController release];