首先更改您的后退按钮操作方法,后退按钮从堆栈中弹出最后一个视图,因此它可能不适用于您的情况,并添加下一个按钮(或使用 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];
请注意,此调用未经测试,您可能会看到一些拼写错误,需要稍微编辑代码