Stop transition to detail view when item is folder.
\r
.DS_Store\r
iOS/Tombo/Tombo.xcodeproj/project.xcworkspace/xcuserdata/\r
+iOS/Tombo/Tombo.xcodeproj/xcuserdata/\r
92DE335B151E277E00AD06EC /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 92DE3359151E277E00AD06EC /* InfoPlist.strings */; };
92DE335E151E277E00AD06EC /* TomboTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 92DE335D151E277E00AD06EC /* TomboTests.m */; };
92DE33861522998700AD06EC /* Storage.m in Sources */ = {isa = PBXBuildFile; fileRef = 92DE33851522998700AD06EC /* Storage.m */; };
+ 92DE338D1522F61200AD06EC /* CustomSegue.m in Sources */ = {isa = PBXBuildFile; fileRef = 92DE338C1522F61200AD06EC /* CustomSegue.m */; };
+ 92DE33901522FFEC00AD06EC /* FileItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 92DE338F1522FFEB00AD06EC /* FileItem.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
92DE335D151E277E00AD06EC /* TomboTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TomboTests.m; sourceTree = "<group>"; };
92DE33841522998700AD06EC /* Storage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Storage.h; sourceTree = "<group>"; };
92DE33851522998700AD06EC /* Storage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Storage.m; sourceTree = "<group>"; };
+ 92DE338B1522F61200AD06EC /* CustomSegue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomSegue.h; sourceTree = "<group>"; };
+ 92DE338C1522F61200AD06EC /* CustomSegue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomSegue.m; sourceTree = "<group>"; };
+ 92DE338E1522FFEB00AD06EC /* FileItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileItem.h; sourceTree = "<group>"; };
+ 92DE338F1522FFEB00AD06EC /* FileItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileItem.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
92DE3333151E277D00AD06EC /* Supporting Files */,
92DE33841522998700AD06EC /* Storage.h */,
92DE33851522998700AD06EC /* Storage.m */,
+ 92DE338E1522FFEB00AD06EC /* FileItem.h */,
+ 92DE338F1522FFEB00AD06EC /* FileItem.m */,
+ 92DE338B1522F61200AD06EC /* CustomSegue.h */,
+ 92DE338C1522F61200AD06EC /* CustomSegue.m */,
);
path = Tombo;
sourceTree = "<group>";
92DE3346151E277D00AD06EC /* MasterViewController.m in Sources */,
92DE3349151E277D00AD06EC /* DetailViewController.m in Sources */,
92DE33861522998700AD06EC /* Storage.m in Sources */,
+ 92DE338D1522F61200AD06EC /* CustomSegue.m in Sources */,
+ 92DE33901522FFEC00AD06EC /* FileItem.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
-//
-// AppDelegate.h
-// Tombo
-//
-// Created by 平見 知久 on 12/03/25.
-// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
-//
-
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
-//
-// AppDelegate.m
-// Tombo
-//
-// Created by 平見 知久 on 12/03/25.
-// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
-//
-
#import "AppDelegate.h"
@implementation AppDelegate
--- /dev/null
+/*
+ * Custom segue
+ *
+ * if isStop is set to YES, transition is disabled.
+ * This segue is used by MainStoryboard_iPhone.
+ */
+#import <UIKit/UIKit.h>
+
+@interface CustomSegue : UIStoryboardSegue
+
+@property BOOL isStop;
+
+@end
--- /dev/null
+#import "CustomSegue.h"
+
+@implementation CustomSegue
+
+@synthesize isStop;
+
+- (void)perform {
+ if (self.isStop) return;
+
+ UINavigationController *ctrl = [self.sourceViewController navigationController];
+ [ctrl pushViewController:self.destinationViewController
+ animated:YES];
+}
+@end
-//
-// DetailViewController.h
-// Tombo
-//
-// Created by 平見 知久 on 12/03/25.
-// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
-//
-
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>
--- /dev/null
+// File/directory placeholder
+
+#import <Foundation/Foundation.h>
+
+@interface FileItem : NSObject
+
+@property NSString *name;
+@property NSString *path;
+@property BOOL isDirectory;
+
+-(NSString*)description;
+
++(id)allocWithName:(NSString *)name;
+
+@end
--- /dev/null
+#import "FileItem.h"
+
+@implementation FileItem
+
+@synthesize name;
+@synthesize path;
+@synthesize isDirectory;
+
+-(NSString*)description {
+ return name;
+}
+
++(id)allocWithName:(NSString *)name {
+ FileItem *fileItem = [FileItem alloc];
+ fileItem.name = name;
+ fileItem.isDirectory = NO;
+ return fileItem;
+}
+
+@end
-//
-// MasterViewController.h
-// Tombo
-//
-// Created by 平見 知久 on 12/03/25.
-// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
-//
-
#import <UIKit/UIKit.h>
@class DetailViewController;
#import "DetailViewController.h"
#import "Storage.h"
+#import "CustomSegue.h"
+#import "FileItem.h"
@interface MasterViewController () {
NSMutableArray *_objects;
}
*/
-// set item (for iPad)
+// Select Row(iPhone/iPad)
+// set item for iPad
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
- NSDate *object = [_objects objectAtIndex:indexPath.row];
- [[segue destinationViewController] setDetailItem:object];
+ FileItem *item = [_objects objectAtIndex:indexPath.row];
+ if (item.isDirectory) {
+ CustomSegue *customSegue = (CustomSegue*)segue;
+ customSegue.isStop = YES;
+ } else {
+ [[segue destinationViewController] setDetailItem:item];
+ }
}
}
@interface Storage : NSObject
+@property NSString *documentRoot;
@property NSString *currentDirectory;
+@property NSFileManager *fileManager;
+ (id)init;
#import "Storage.h"
+#import "FileItem.h"
@implementation Storage
@synthesize currentDirectory;
+@synthesize documentRoot;
+@synthesize fileManager;
+(id)init {
Storage *storage = [Storage alloc];
- storage.currentDirectory = @"";
+ storage.currentDirectory = @"/";
+
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+ storage.documentRoot = [paths objectAtIndex:0];
+
+ storage.fileManager = [NSFileManager defaultManager];
+
return storage;
}
+/*
+ * Enumerate current directory and return array of FileItem.
+ */
-(NSArray*)listItems {
- return [NSArray arrayWithObjects:@"abc", @"def", @"ghi", @"jkl", @"mno", @"pqr", nil];
+ NSError *error = nil;
+ NSString *currentPath = [documentRoot stringByAppendingString: currentDirectory];
+ NSArray *files = [fileManager contentsOfDirectoryAtPath: currentPath
+ error: &error];
+ if (error) {
+ return [NSArray alloc];
+ }
+
+ NSMutableArray *result = [NSMutableArray arrayWithCapacity: files.count];
+ for (NSString *f in files) {
+ FileItem *item = [FileItem alloc];
+ item.path = [currentPath stringByAppendingString: f];
+ item.name = [f stringByDeletingPathExtension];
+ BOOL bDir = NO;
+ [fileManager fileExistsAtPath:item.path isDirectory:&bDir];
+ item.isDirectory = bDir;
+ [result addObject:item];
+ }
+ return result;
}
@end
</view>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<connections>
- <segue destination="21" kind="push" identifier="showDetail" id="jZb-fq-zAk"/>
+ <segue destination="21" kind="custom" identifier="showDetail" customClass="CustomSegue" id="jZb-fq-zAk"/>
</connections>
</tableViewCell>
</prototypes>
<placeholder placeholderIdentifier="IBFirstResponder" id="23" sceneMemberID="firstResponder"/>
<viewController storyboardIdentifier="" title="Detail" id="21" customClass="DetailViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="22">
- <rect key="frame" x="0.0" y="64" width="320" height="416"/>
+ <rect key="frame" x="0.0" y="20" width="320" height="460"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="dcM-3R-DB6">
- <rect key="frame" x="0.0" y="0.0" width="320" height="416"/>
+ <rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<point key="canvasLocation" x="902" y="64"/>
</scene>
</scenes>
+ <classes>
+ <class className="DetailViewController" superclassName="UIViewController">
+ <source key="sourceIdentifier" type="project" relativePath="./Classes/DetailViewController.h"/>
+ <relationships>
+ <relationship kind="outlet" name="detailText" candidateClass="UITextView"/>
+ </relationships>
+ </class>
+ <class className="MasterViewController" superclassName="UITableViewController">
+ <source key="sourceIdentifier" type="project" relativePath="./Classes/MasterViewController.h"/>
+ </class>
+ </classes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
-</document>
\ No newline at end of file
+</document>
-//
-// main.m
-// Tombo
-//
-// Created by 平見 知久 on 12/03/25.
-// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
-//
-
#import <UIKit/UIKit.h>
#import "AppDelegate.h"