IOS --- 读取本地文件

#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


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值