<<本code只po片段, 非完整AP>>
首先有一個Table View塞了一些資料
//.h檔要先宣告
//@property (strong, nonatomic) 記憶體位置形態 *titlePosition;
//@property (strong, nonatomic) 記憶體位置形態 *backName;
//@property (strong, nonatomic) NSMutableArray *folderList;
//@property (strong, nonatomic) NSMutableArray *backNameArray;
//@property (weak, nonatomic) IBOutlet UINavigationItem *topNavigationItem;
//@property (weak, nonatomic) IBOutlet UINavigationItem *bottomNavigationItem;
//@property (weak, nonatomic) IBOutlet UITableView *fileListTableView;
//@property (strong, nonatomic) SSPullToRefreshView *pullToRefresh;
@synthesize titlePosition;
@synthesize destinationNavigationItem;
@synthesize backName;
@synthesize folderList;
@synthesize backNameArray;
@synthesize topNavigationItem;
@synthesize bottomNavigationItem;
@synthesize fileListTableView;
@synthesize pullToRefresh;
//此頁面第一次開啓時
- (void)viewDidLoad
{
[super viewDidLoad];
//parentParentIDArray = [[NSMutableArray alloc] init];
//titlePosition表記憶體位置, 沒有值, 代表位於根目錄
if (!titlePosition)
{
//取得根目錄下所有檔案, 方法不詳述
fileList = [self getFileListByTitlePosition:nil];
topNavigationItem.title = @"根目錄";
topNavigationItem.leftBarButtonItem.enabled = NO;
bottomNavigationItem.rightBarButtonItem.enabled = NO;
}
else
{
topNavigationItem.title = titlePosition.name;
fileList = [self getFileListByTitlePosition:titlePosition];
//設定Navigation Controller的backButton行為
if(backPositionArray.count > 1)
{
backPosition = [backPositionArray objectAtIndex:backPositionArray.count-1];topNavigationItem.leftBarButtonItem.title = backPosition.name;
}
else
{
backPosition = nil;
topNavigationItem.leftBarButtonItem.title = @"根目錄";
}
}
}
//點擊Table View上某筆資料的觸發事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
記憶體位置形態 *position = nil;
//根據user點選到的data儲存為position
position = [folderList objectAtIndex:indexPath.row];
//若上一層為根目錄
if(!titlePosition){
backPositionArray = [[NSMutableArray alloc] init];
[backPositionArray addObject:@""];
}//否則將上一層的titlePosition存進Array備用
else
{
[backPositionArray addObject:titlePosition];
}
//若user點選到的是目錄, 應展開底層資料
if ([position.file_type isEqualToString:TYPE_FOLDER]) {
//先將上一層的titlePosition指給backPosition
backPosition = titlePosition;
topNavigationItem.leftBarButtonItem.title = backPosition.name;//將這次user點到的Position指給titlePosition
titlePosition = Position;
topNavigationItem.title = titlePosition.name;
//根據titlePosition取得這一層的fileList
fileList = [self getFileListByTitlePosition:titlePosition];
//更新畫面
pullToRefresh = [[SSPullToRefreshView alloc] initWithScrollView:self.fileListTableView delegate:self];
}
}
- (void)pullToRefreshViewDidStartLoading:(SSPullToRefreshView *)view
{
//更新方式不詳述
[self refresh];
}
//click 返回上一頁
- (IBAction)backButton:(id)sender
{
//backButton上的名稱要給topNavigationItem.title
//若backPositionArray只剩下一筆資料
else
{
titlePosition = nil;
topNavigationItem.title = @"根目錄";
{
//更新方式不詳述
[self refresh];
}
//click 返回上一頁
- (IBAction)backButton:(id)sender
{
if(backPositionArray.count > 1)
{//backButton上的名稱要給topNavigationItem.title
titlePosition = backPosition;
topNavigationItem.title = titlePosition.name;
//由於是返回上一層, backPositionArray-1
[backPositionArray removeObjectAtIndex:backPositionArray.count-1];
backPosition = [backPositionArray objectAtIndex:backPositionArray.count-1];
topNavigationItem.leftBarButtonItem.title = backPosition.name;
fileList = [self getFileListByTitlePosition:titlePosition];
} //若backPositionArray只剩下一筆資料
else
{
titlePosition = nil;
topNavigationItem.title = @"根目錄";
//由於是返回上一層, backPositionArray-1
[backPositionArray removeObjectAtIndex:backPositionArray.count-1];
backPosition = nil;
topNavigationItem.leftBarButtonItem.title = @"";
bottomNavigationItem.rightBarButtonItem.enabled = NO;
topNavigationItem.leftBarButtonItem.enabled = NO;
fileList = [self getFileListByTitlePosition:titlePosition];
}
//更新畫面
pullToRefresh = [[SSPullToRefreshView alloc] initWithScrollView:self.fileListTableView delegate:self];
}
沒有留言:
張貼留言