IOS --- 读取本地文件
来源:互联网 发布:服务器负载均衡软件 编辑:程序博客网 时间:2024/06/07 03:19
#import "BIDDirectoryViewController.h"
@interface BIDDirectoryViewController ()
@property(nonatomic,retain)UIBarButtonItem *upload;
@end
@implementation BIDDirectoryViewController
- (id)initWithStyle:(UITableViewStyle)style WithDirectoryPath:(NSString*) p
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
_upload = [[UIBarButtonItem alloc]initWithTitle:@"upload" style:UIBarButtonItemStylePlain target:self action:@selector(uploadFile:)];
self.navigationItem.rightBarButtonItem = _upload;
self.directoryPath = p;
[self loadDirectoryContents];
NSString *pathTitle = [self.directoryPath lastPathComponent];
self.title = pathTitle;
}
return self;
}
-(void)uploadFile:(id) sender
{
}
-(void)loadDirectoryContents
{
_directoryContents = [[NSMutableArray alloc]init];
_directoryContents = [[NSFileManager defaultManager]directoryContentsAtPath:self.directoryPath];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return [_directoryContents count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if(cell==nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *selectedFile = (NSString*)[_directoryContents objectAtIndex:indexPath.row];
BOOL isDir;
NSString *selectedPath = [self.directoryPath stringByAppendingPathComponent:selectedFile];
if([[NSFileManager defaultManager]fileExistsAtPath:selectedPath isDirectory:&isDir] &&isDir){
cell.imageView.image = [UIImage imageNamed:@"1.png"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}else{
cell.accessoryType = UITableViewCellAccessoryNone;
cell.imageView.image =[UIImage imageNamed:@"2.png"];
}
cell.textLabel.text = selectedFile;
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
NSString *selectedFile = (NSString*)[_directoryContents objectAtIndex:indexPath.row];
BOOL isDir;
NSString *selectedPath = [self.directoryPath stringByAppendingPathComponent:selectedFile];
if([[NSFileManager defaultManager]fileExistsAtPath:selectedPath isDirectory:&isDir] &&isDir)
{
BIDDirectoryViewController *directoryController = [[BIDDirectoryViewController alloc]initWithStyle:UITableViewStylePlain WithDirectoryPath:selectedPath];
[[self navigationController]pushViewController:directoryController animated:YES];
//directoryController.directoryPath = selectedPath;
}else{
//
// BIDFileOverviewViewController *fileController = [[BIDFileOverviewViewController alloc]initWithStyle:UITableViewStylePlain WithFilePath:selectedPath];
//[[self navigationController]pushViewController:fileController animated:YES];
}
}
@end
@interface BIDDirectoryViewController ()
@property(nonatomic,retain)UIBarButtonItem *upload;
@end
@implementation BIDDirectoryViewController
- (id)initWithStyle:(UITableViewStyle)style WithDirectoryPath:(NSString*) p
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
_upload = [[UIBarButtonItem alloc]initWithTitle:@"upload" style:UIBarButtonItemStylePlain target:self action:@selector(uploadFile:)];
self.navigationItem.rightBarButtonItem = _upload;
self.directoryPath = p;
[self loadDirectoryContents];
NSString *pathTitle = [self.directoryPath lastPathComponent];
self.title = pathTitle;
}
return self;
}
-(void)uploadFile:(id) sender
{
}
-(void)loadDirectoryContents
{
_directoryContents = [[NSMutableArray alloc]init];
_directoryContents = [[NSFileManager defaultManager]directoryContentsAtPath:self.directoryPath];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return [_directoryContents count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if(cell==nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *selectedFile = (NSString*)[_directoryContents objectAtIndex:indexPath.row];
BOOL isDir;
NSString *selectedPath = [self.directoryPath stringByAppendingPathComponent:selectedFile];
if([[NSFileManager defaultManager]fileExistsAtPath:selectedPath isDirectory:&isDir] &&isDir){
cell.imageView.image = [UIImage imageNamed:@"1.png"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}else{
cell.accessoryType = UITableViewCellAccessoryNone;
cell.imageView.image =[UIImage imageNamed:@"2.png"];
}
cell.textLabel.text = selectedFile;
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
NSString *selectedFile = (NSString*)[_directoryContents objectAtIndex:indexPath.row];
BOOL isDir;
NSString *selectedPath = [self.directoryPath stringByAppendingPathComponent:selectedFile];
if([[NSFileManager defaultManager]fileExistsAtPath:selectedPath isDirectory:&isDir] &&isDir)
{
BIDDirectoryViewController *directoryController = [[BIDDirectoryViewController alloc]initWithStyle:UITableViewStylePlain WithDirectoryPath:selectedPath];
[[self navigationController]pushViewController:directoryController animated:YES];
//directoryController.directoryPath = selectedPath;
}else{
//
// BIDFileOverviewViewController *fileController = [[BIDFileOverviewViewController alloc]initWithStyle:UITableViewStylePlain WithFilePath:selectedPath];
//[[self navigationController]pushViewController:fileController animated:YES];
}
}
@end
- IOS --- 读取本地文件
- IOS读取本地文件内容
- 在iOS中读取本地文件
- ios本地文件读取,json解析YYModel
- 读取本地文件
- 读取本地文件
- 读取本地文件
- 读取json 读取本地文件
- Unity3D IOS Android支持中文与本地文件的读取写入
- ios本地文件内容读取,.json .plist 文件读写
- iOS 本地文件
- MSSQL 读取本地文件数据
- JAVASCRIPT 读取本地文件
- js读取本地文件
- js读取本地文件
- Flex 实现读取本地文件
- flex实现读取本地文件
- AIR读取本地文件
- 信号与信息承载
- android用户界面之ProgressBar教程实例汇总
- 线程系列五
- 一个还不成熟的makefile工程
- Eclipse 不在左边显示导入的jar包
- IOS --- 读取本地文件
- POJ 1469 COURSES【匈牙利算法入门 二分图的最大匹配 模板题】
- MySql-MSSQL数据库复制表数据
- pkg-config与LD_LIBRARY_PATH
- rageagainstthecage.c源代码
- onerasebabkgnd
- shell正则表达式介绍
- 索尼笔记本如何进Bios设置U盘启动
- Git的Patch功能