我正在尝试使用故事板找到用于浏览远程文件系统(dropbox)的解决方案。例如,如果用户点击浏览文件夹,则没有关于文件夹结构有多深的信息。我的意思是该文件夹可能包含另一个文件夹,另一个可能包含另一个文件夹,它可以转到5,10,20等。这使得无法定义我应该添加多少个tableview控制器我的故事板。我尝试只使用一个并使用以下代码为每个选定的文件夹更新相同的tableview:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[dropBoxArray removeAllObjects]; //remove all the objects which comes from the previous folder structure
[[self restClient] loadMetadata:@"/selected folder/"]; // load the newly selected folder
contents
}
它只适用于一个方向,用户可以直接浏览文件夹树,但这次不可能一步一步地返回。因为导航控制器将后退按钮放在导航项上,并且它加载上一个视图而不是上一个目录。 我无法找到如何正确处理这种逻辑并需要帮助。
答案 0 :(得分:0)
首先改变你的后退按钮动作方法,后退按钮从堆栈中弹出最后一个视图,这样它可能在你的情况下不起作用,并且还添加一个下一个按钮(或者使用didselect行对你有用)
第二次使用单例类来保存文件夹路径。
接下来将添加一个详细信息文件夹添加到您的元数据路径selected folder/detail folder
,然后返回将删除最后一个路径selected folder/
将单例类添加到代码中:
#import <Foundation/Foundation.h>
@interface SingletonClass : NSObject
{
NSString *lastCreatedFolderName;
NSMutableArray *fileListForEdit;
}
@property (nonatomic, retain) NSString *lastCreatedFolderName;
@property (nonatomic, retain) NSMutableArray *fileListForEdit;
+ (SingletonClass *)sharedInstance;
@end
#import "SingletonClass.h"
@implementation SingletonClass
@synthesize lastCreatedFolderName=_lastCreatedFolderName;
@synthesize fileListForEdit=_fileListForEdit;
+ (SingletonClass *)sharedInstance
{
static SingletonClass *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[SingletonClass alloc] init];
// Do any other initialisation stuff here
});
return sharedInstance;
}
- (id)init {
if (self = [super init]) {
_lastCreatedFolderName = @"Empty Folder";
_fileListForEdit=[[NSMutableArray alloc]init];
}
return self;
}
-(NSString *) addFolderPath : (NSString *) nextFolder{
[_fileListForEdit addObject:nextFolder]; // add your folder path to mutablearray
for(int i=0 ; int<[_fileListForEdit count]; i++) {
_lastCreatedFolderName=[NSString stringWithFormat:@"%@/%@",_lastCreatedFolderName,[_fileListForEdit objectAtIndex:i]]; //add folder path to your current path
}
return _lastCreatedFolderName;
}
-(NSString *) removeLastFolderDromPath
{
[_fileListForEdit removeLastObject];// remove last folder path from array
//create new folder path
for(int i=0 ; int<[_fileListForEdit count]; i++) {
_lastCreatedFolderName=[NSString stringWithFormat:@"%@/%@",_lastCreatedFolderName,[_fileListForEdit objectAtIndex:i]]; //add folder path to your current path
}
return _lastCreatedFolderName;
}
@end
In - (void)loadView:
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:@selector(backPressed:)];
self.navigationItem.leftBarButtonItem = btn;
UIBarButtonItem *btnNext = [[UIBarButtonItem alloc] initWithTitle:@"next" style:UIBarButtonItemStyleBordered target:self action:@selector(nextPressed:)];
self.navigationItem.rightBarButtonItem = btnNext;
-(void)backPressed: (id)sender
{
//call your singleton here and load last path
SingletonClass *sharedInstance=[SingletonClass sharedInstance];
NSString *destDirectory= [sharedInstance addFolderPath :@"nextFolder"];
}
-(void)nextPressed: (id)sender
{
//call your singleton here and load last path
//get last created file name from singleton
SingletonClass *sharedInstance=[SingletonClass sharedInstance];
NSString *destDirectory= [sharedInstance removeLastFolderDromPath];//gives you the new path
}
然后用
打电话给你的客户 [[self restClient] loadMetadata:destDirectory];
请注意,此次调用未经过测试,您可能会看到一些拼写错误并需要稍微编辑代码