3

我正在尝试使用情节提要找到用于浏览远程文件系统(保管箱)的解决方案。例如,如果用户点击浏览文件夹,则没有关于文件夹结构深度的信息。我的意思是文件夹可能包含另一个文件夹,另一个文件夹可能包含另一个文件夹,它可以转到 5、10、20 等。这使得我无法定义我应该添加多少个 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
}

它只适用于一个方向,用户可以浏览文件夹树直到永远,但这一次不可能一步一步返回。因为导航控制器将后退按钮放在导航项上,它会加载上一个视图而不是上层目录。我找不到如何正确处理这个逻辑并且需要帮助。

4

1 回答 1

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

在 -(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];

请注意,此调用未经测试,您可能会看到一些拼写错误,需要稍微编辑代码

于 2013-01-16T16:59:02.907 回答